Replies: 4 comments 2 replies
-
|
Trying to solve the same problem myself. Migrating from a SPA and route-based approach is a no-no. Server side seems to be pretty straightforward, just try to get locale from a cookie, then headers or fall back to default. The big question is how to create some sort of a shared context as a single source of truth between the server and client components. Looking at Jotai as a potential solution right now. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @vktrl, I'm just wondering if you had found any approach to this issue? I'm planning the migration to the app directory, and the translations are my biggest concern. The "offical" example with a query parameter or a dynamic [lang] routing segment at the root level just seem so clunky. |
Beta Was this translation helpful? Give feedback.
-
|
+1 on this! |
Beta Was this translation helpful? Give feedback.
-
|
For anyone looking in to this, next-translate is truly awesome. Thats it! (Using App-folder) Edit: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It really surprises me that everyone's only talking about setting locales like
site.com/en/whatever. In our app, we are using a cookie, which seems to be a pretty common thing.With the
pagesdirectory, I could just take thecontextingetServerSideProps, determine the necessary locale, then docontext.locale = 'language', and it worked.Now it seems like there's no such thing as context anymore. I can get cookies, but not change the locale.
next-translatedocs have an example that mentions rewriting the request adding alangsearch param using a middleware. But is this really the recommended way to solve this? It feels like rewriting requests to add fake i18n stuff is a hack and shouldn't be necessary, considering locale in our app has nothing to do with paths.I mean, can't we just read the cookie and set the locale without any of that? I'm not sure how exactly it is done right now, but having some sort of centralized way to set the locale for the current page during server rendering would be great. I see that
next-translatehas its own cookie to store the user preference (does it work with theappdirectory?), but I need the locale to be correct right away, on the first load (some deployments of the app have a fixed locale).Just want to hear your perspective, if I'm maybe overlooking some feature of
next-translateor you see some way to implement this behavior.Beta Was this translation helpful? Give feedback.
All reactions