Reputation: 818
I am trying to translate my Next app based on the current sub-domain. For example, I would like en.hello.com
to be in English, and it.hello.com
to be in Italian.
I am trying to achieve that using Next's domain routing, but apparently, that is not meant to be used with sub-domains but rather with top-level domains like hello.en
and hello.it
for English and Italian for example.
Here is my next.config.js:
module.exports = {
i18n: {
locales: ["en", "it"],
defaultLocale: "en",
domains: [
{
domain: "en.hello.com",
defaultLocale: "en",
},
{
domain: "it.hello.com",
defaultLocale: "it",
},
],
},
};
These settings fail to map en.hello.com
to English and it.hello.com
to Italian.
Can anybody explain why that is and how can I achieve sub-domain routing in Next?
Upvotes: 5
Views: 5678
Reputation: 1370
What you're trying to do does not seem to be a supported feature. Per your own provided documentation, you can have either a top level locale domain such as .it
or a sub-path such as /it
. Now i'm not sure why you want a subdomain when majority of websites on the internet are opting for the sub-path. If you choose sub-path, then by providing the Accept-Language: it;q=0.9
header user will be redirected automatically.
Alternative
If you're unable to utilize either of supported features, then your only other option is to create custom servers. This comes with a lot more work and you'll also lose the ability to deploy to vercel platform.
Upvotes: 2