Next.js, i18n - 2 domains with the save default locale

Viewed 124

I have a Next.js site (with plans to host it on Vercel, not that it's relevant..) and I'd like to set up different default locales on different domains. Here is my (redacted) next.config.js:

module.exports = {
    i18n: {
        locales: ['en', 'cs'],
        defaultLocale: 'en',
        localeDetection: true,
        domains: [{
            domain: 'humanely.it',
            defaultLocale: 'en',
        }, {
            domain: 'lidsky.it',
            defaultLocale: 'cs',
        }, {
            domain: 'itlidsky.cz',
            defaultLocale: 'cs',
        }],
    },
}

...and here's the error:

Both lidsky.it and itlidsky.cz configured the defaultLocale cs but only one can. Change one item's default locale to continue
Both itlidsky.cz and lidsky.it configured the defaultLocale cs but only one can. Change one item's default locale to continue
Error: Invalid i18n.domains values:
{"domain":"lidsky.it","defaultLocale":"cs"}
{"domain":"itlidsky.cz","defaultLocale":"cs"}

I understand what the error is saying perfectly well - the thing is... seriously??? Did I miss something or does it actually, seriously mean that no 2 domains can have the same default locale configured? I mean, I see zero reasons why 2 different domains can't have the same default locale.

Can I somehow configure the same default locale for 2 domains, or is this a deliberate defect on part of Next.js?

1 Answers

Not sure why the comment with the right answer disappeared, but to anyone who's interested:

This is expected behavior. If I read the documentation properly, I'd find out that the multidomain configuration is not intended for language detection, but rather a redirect to a specific domain when the user changes the language. Therefore having two domains with the same language does not make sense - each language can have only 1 domain so that the user can be redirected to it.

(sorry to the person who provided me with the correct answer - your comment disappeared and I don't remember your nickname )

Related