You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today I used patch-package to patch ni18n@1.0.5 for the project I'm working on.
I need to set the locale upon i18next instance init on Next.js during server-side rendering to avoid hydration issues. To do this, I tried using different i18next plugins to get the locale from the cookies, but none worked. Next.js's native locale management didn't help either as they have very aggressive defaults that will take over the lcoale or assign its own config defaults.
What I did to solve this was to get the locale value from the cookies in a middleware, pass the locale to the pageProps and this is then read in the init step using the HOC provided by ni18n.
Here is the diff that solved my problem. I know it should be made more configurable, right now the property for language in pageProps is hardcoded.
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
ni18n@1.0.5
for the project I'm working on.I need to set the locale upon
i18next
instance init on Next.js during server-side rendering to avoid hydration issues. To do this, I tried using differenti18next
plugins to get the locale from the cookies, but none worked. Next.js's native locale management didn't help either as they have very aggressive defaults that will take over the lcoale or assign its own config defaults.What I did to solve this was to get the locale value from the cookies in a middleware, pass the locale to the pageProps and this is then read in the init step using the HOC provided by
ni18n
.Here is the diff that solved my problem. I know it should be made more configurable, right now the property for language in pageProps is hardcoded.
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: