Multi-channel, multi-locale support #1776
-
Is your feature request related to a problem? Please describe.I am looking for a way in Next.js to handle a multi-channel, multi-locale website. Awesome work on this package for multi-locale websites! We're going to build a e-commerce website for over 10+ countries with each of them having one or more languages. One country can also have multiple channels for specific products. So for example: the Belgium website in french is different than the french website. They have the same language but can have different settings, menus, products etc. So we need a multi-channel, multi-locale website and I would like to implement that with next-intl. For now I found a workaround abusing the locales to achieve this. Would love to hear you thoughts on this! And the feature request is to have some solution for this native in Describe the solution you'd likeSolutionI found the solution in extending the routing.ts locales. I extend the locale with a string structure like this: Routing.ts
Locale transformerTo transform the locale in useful parts i have this transformer to get the
Page.tsxThen in my pages i can use this function to get the desired consts and use them for messages, api calls, etc.
ConclusionThis works quite nice for now and it is pretty simple to implement. I didn't need to do any modifications to the middleware. Describe alternatives you've consideredAn alternative I considered was adding another dynamic path like
But for this to work i had to rewrite the complete middleware. That's something i want to avoid because the current middleware works really well! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey, thanks for the thoughtful question!
So locales are really required to be valid IETF language tags. In v3 some features work even for invalid locales but others will break. In v4 (will be released soon), there will be an upfront warning when you're using invalid locales. That being said, you can encode quite a bit into locales, including private, arbitrary information—so that should hopefully let you provide e.g. a differentiator for different German stores. In combination with custom prefixes and a locale prefix config, I think this should get you pretty far! You can then extract your channel from the locale and use it as necessary in code. Hope this helps, sounds like a really exciting project! 🙌 |
Beta Was this translation helpful? Give feedback.
-
I'll move this to a discussion since it seems to be more of a usage question … |
Beta Was this translation helpful? Give feedback.
Hey, thanks for the thoughtful question!
So locales are really required to be valid IETF language tags. In v3 some features work even for invalid locales but others will break. In v4 (will be released soon), there will be an upfront warning when you're using invalid locales.
That being said, you can encode quite a bit into locales, including private, arbitrary information—so that should hopefully let you provide e.g. a differentiator for different German stores.
In combination with custom prefixes and a locale prefix config, I think this should get you pretty far! You can then extract your channel from the locale and use it as necessary in code.
Hope this helps, …