Last active
October 14, 2024 22:38
-
-
Save daliborgogic/1b3b7468d1afb8a67bcab7ca2091a705 to your computer and use it in GitHub Desktop.
132 bytes i18n in Nuxt.js
This file contains 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 function useI18n(translations) { | |
// return (key, ...args) => { | |
// const value = key.trim().split('.').reduce((obj, k) => obj?.[k], translations) ?? key | |
// return typeof value === 'function' ? value(...args) : value | |
// } | |
// } | |
export function useI18n(t){return(n,...e)=>{const r=n.trim().split('.').reduce(((t,n)=>t?.[n]),t)??n;return'function'==typeof r?r(...e):r}} | |
export const t = (x, y) => useRoute().meta.t(x, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage