Last active
October 26, 2022 18:34
-
-
Save daliborgogic/14a7bb7fb2d1b0f588b5cfb940c6c1ed to your computer and use it in GitHub Desktop.
[POC] i18n in 142 bytes π₯
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function (locale, path, ...args) { | |
return (path, ...args) => { | |
const keys = path.trim().split('.') | |
const fn = keys.reduce((prev, curr) => prev && prev[curr], locale) | |
return typeof fn === 'function' ? fn(...args) : fn | |
} | |
} | |
// export default function(t,e,...n){return(e,...n)=>{const r=e.trim().split(".").reduce((t,e)=>t&&t[e],t);return"function"==typeof r?r(...n):r}} |
Author
daliborgogic
commented
Nov 6, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment