Skip to content

What's the suggested way to set the locale with the app directory without using paths?Β #1025

@finkrer

Description

@finkrer

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 pages directory, I could just take the context in getServerSideProps, determine the necessary locale, then do context.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-translate docs have an example that mentions rewriting the request adding a lang search 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-translate has its own cookie to store the user preference (does it work with the app directory?), 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-translate or you see some way to implement this behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions