Last active
October 14, 2024 22:38
Revisions
-
daliborgogic revised this gist
Oct 14, 2024 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,7 @@ // 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}} -
daliborgogic revised this gist
Oct 14, 2024 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,9 @@ // export function useI18n(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 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) -
daliborgogic revised this gist
Oct 14, 2024 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,2 @@ 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) -
daliborgogic revised this gist
Oct 14, 2024 . No changes.There are no files selected for viewing
-
daliborgogic revised this gist
Oct 14, 2024 . 2 changed files with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,2 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ // 132 bytes 💥 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) -
daliborgogic revised this gist
Oct 14, 2024 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,2 @@ // 132 bytes 💥 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}} -
daliborgogic revised this gist
Oct 14, 2024 . 1 changed file with 1 addition and 22 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,2 @@ // 137 bytes 💥 function useI18n(t,e,...n){return(e,...n)=>{let r=e.trim().split('.'),u=r.reduce((t,e)=>t&&t[e],t);return'function'==typeof u?u(...n):u}} -
daliborgogic revised this gist
Oct 14, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ export default defineNuxtRouteMiddleware(async (to) => { const DEFAUT_LANGUAGE = 'en' const supportedLanguages = ['sr', 'de'] const { lang } = to.params const isLang = supportedLanguages.includes(lang) const filename = isLang ? lang : DEFAUT_LANGUAGE const { default: locale } = await import(`./../i18n/${to.name}/${filename}.js`) // DE -
daliborgogic revised this gist
Oct 14, 2024 . 1 changed file with 13 additions and 19 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,23 +7,17 @@ export default defineNuxtRouteMiddleware(async (to) => { const supportedLanguages = ['sr', 'de'] const { lang } = to.params const isLang = supportedLanguages.includes(lang as string) const filename = isLang ? lang : DEFAUT_LANGUAGE const { default: locale } = await import(`./../i18n/${to.name}/${filename}.js`) // DE // { // welcome: 'Willkommen!', // hello: x => `Hallo ${x}!`, // colors: [ // 'Weiß', // 'Schwarz' // ] // } const t = useI18n(locale) to.meta = { t } }) -
daliborgogic revised this gist
Oct 14, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // 137 bytes 💥 function useI18n(t,e,...n){return(e,...n)=>{let r=e.trim().split('.'),u=r.reduce((t,e)=>t&&t[e],t);return'function'==typeof u?u(...n):u}} // Usage in Nuxt.js -
daliborgogic revised this gist
Oct 14, 2024 . No changes.There are no files selected for viewing
-
daliborgogic revised this gist
Oct 14, 2024 . No changes.There are no files selected for viewing
-
daliborgogic revised this gist
Oct 14, 2024 . 1 changed file with 5 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,7 @@ // 137 bytes function useI18n(t,e,...n){return(e,...n)=>{let r=e.trim().split('.'),u=r.reduce((t,e)=>t&&t[e],t);return'function'==typeof u?u(...n):u}} // Usage in Nuxt.js export default defineNuxtRouteMiddleware(async (to) => { const DEFAUT_LANGUAGE = 'en' const supportedLanguages = ['sr', 'de'] @@ -15,6 +10,8 @@ export default defineNuxtRouteMiddleware(async (to) => { try { const filename = isLang ? lang : DEFAUT_LANGUAGE const { default: locale } = await import(`./../i18n/${to.name}/${filename}.js`) // DE // { // welcome: 'Willkommen!', // hello: x => `Hallo ${x}!`, @@ -23,7 +20,6 @@ export default defineNuxtRouteMiddleware(async (to) => { // 'Schwarz' // ] // } const t = useI18n(locale) to.meta = { t } } catch (error) { -
daliborgogic revised this gist
Oct 9, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ // 142 bytes function useI18n(locale, path, ...args) { return (path, ...args) => { const keys = path.trim().split('.') -
daliborgogic renamed this gist
Oct 9, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
daliborgogic revised this gist
Oct 9, 2024 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -14,6 +14,14 @@ export default defineNuxtRouteMiddleware(async (to) => { try { const filename = isLang ? lang : DEFAUT_LANGUAGE // { // welcome: 'Willkommen!', // hello: x => `Hallo ${x}!`, // colors: [ // 'Weiß', // 'Schwarz' // ] // } const { default: locale } = await import(`./../i18n/${to.name}/${filename}.js`) const t = useI18n(locale) to.meta = { t } -
daliborgogic revised this gist
Oct 9, 2024 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,6 @@ function useI18n(locale, path, ...args) { export default defineNuxtRouteMiddleware(async (to) => { const DEFAUT_LANGUAGE = 'en' const supportedLanguages = ['sr', 'de'] const { lang } = to.params const isLang = supportedLanguages.includes(lang as string) -
daliborgogic revised this gist
Oct 9, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ function useI18n(locale, path, ...args) { export default defineNuxtRouteMiddleware(async (to) => { const DEFAUT_LANGUAGE = 'en' const supportedLanguages = ['sr', 'de'] const allowedRouteNames = ['lang-login', 'lang-terms', 'lang-privacy'] const { lang } = to.params const isLang = supportedLanguages.includes(lang as string) -
daliborgogic revised this gist
Oct 9, 2024 . 1 changed file with 1 addition and 26 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,36 +8,11 @@ function useI18n(locale, path, ...args) { export default defineNuxtRouteMiddleware(async (to) => { const DEFAUT_LANGUAGE = 'en' const supportedLanguages = ['sr'] const allowedRouteNames = ['lang-login', 'lang-terms', 'lang-privacy'] const { lang } = to.params const isLang = supportedLanguages.includes(lang as string) try { const filename = isLang ? lang : DEFAUT_LANGUAGE const { default: locale } = await import(`./../i18n/${to.name}/${filename}.js`) -
daliborgogic revised this gist
Oct 9, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ function useI18n(locale, path, ...args) { export default defineNuxtRouteMiddleware(async (to) => { const DEFAUT_LANGUAGE = 'en' const supportedLanguages = ['sr'] // more provided soon const allowedRouteNames = ['lang-login', 'lang-terms', 'lang-privacy'] const { loggedIn, user } = useUserSession() const { lang } = to.params const isLang = supportedLanguages.includes(lang as string) -
daliborgogic revised this gist
Oct 9, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ function useI18n(locale, path, ...args) { return (path, ...args) => { const keys = path.trim().split('.') const fn = keys.reduce((prev, curr) => prev && prev[curr], locale) -
daliborgogic revised this gist
Oct 9, 2024 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,11 @@ export function useI18n(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 defineNuxtRouteMiddleware(async (to) => { const DEFAUT_LANGUAGE = 'en' const supportedLanguages = ['sr'] // more provided soon @@ -33,7 +41,8 @@ export default defineNuxtRouteMiddleware(async (to) => { try { const filename = isLang ? lang : DEFAUT_LANGUAGE const { default: locale } = await import(`./../i18n/${to.name}/${filename}.js`) const t = useI18n(locale) to.meta = { t } } catch (error) { // ToDo: handle error console.error(error) -
daliborgogic created this gist
Oct 9, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ export default defineNuxtRouteMiddleware(async (to) => { const DEFAUT_LANGUAGE = 'en' const supportedLanguages = ['sr'] // more provided soon const allowedRouteNames = ['login', 'terms', 'privacy'] const { loggedIn, user } = useUserSession() const { lang } = to.params const isLang = supportedLanguages.includes(lang as string) if (!loggedIn.value && !allowedRouteNames.includes(to.name as string)) { return navigateTo('/login') } const isTestRoute = computed(() => (to.name as string).startsWith('lang-test')) const isTestMode = computed(() => user.value.mode === 'test') const testParam = computed(() => isTestMode.value ? 'test' : '') if (to.name === 'lang' && isTestMode.value) { return navigateTo({ name: isTestMode.value ? 'lang-test' : 'lang', params: { lang: isLang ? lang : '' } }) } if (isTestRoute.value && testParam.value !== to.params.test) { return navigateTo({ name: to.name, params: { ...to.params, test: testParam.value, lang: isLang ? lang : '' } }) } try { const filename = isLang ? lang : DEFAUT_LANGUAGE const { default: locale } = await import(`./../i18n/${to.name}/${filename}.js`) to.meta = { locale } } catch (error) { // ToDo: handle error console.error(error) } })