Here's my current function :
export const t = (locale, nsKey) => {
const dictionary = getDictionary(locale)
return getNestedValue(dictionary, nsKey)
}
^ This function intents are to reproduce i18n feature.. to be able to get text from a key like that :
t('form.classic.name')
But in my function, i've to specify the lang, and I want to get rid of that :
My idea was to use typeof window === undefined
to know if i'm in a client component or in a server one
But there's still a main problem :
how i could get the langage...
- In my server's components, i've setup a server-context, that can provide the langage.. cool But i can't use it in a Client Component, or i will get a runtime error
- In my client components, i don't know, i usually use the
usePathname
hooks, but i can't use it out of a component and i can't use it by not specifying theuse client
directive
Any idea to how i can solve my problem ?
Using App Router :nerd: