N
Nuxt3mo ago
Inès

Have multiple domains use the same locale

Hello, I'm dealing with some i18n configuration in my nuxt 3.11 project at the moment. In my nuxt.config.ts file I have (development configuration):
i18n: { strategy: 'no_prefix', differentDomains: true, detectBrowserLanguage: false, locales: [ { code: 'de', domain: 'http://de.localhost:3002' }, { code: 'en', domain: 'http://en.localhost:3002' }, { code: 'en-US', domain: 'http://localhost:3002' }, { code: 'en-GB', domain: 'http://www.localhost:3002' } ] },
My i18n.config.ts resembles this:
export default defineI18nConfig(() => ({ legacy: false, globalInjection: true, fallbackLocale: 'en', messages: { en, 'en-GB': en, 'en-US': en, de } }))
I wonder how I could achieve different domains pointing to the same locale (e.g. de-DE and de-AT pointing to de messages in fine)? Many thanks!
10 Replies
xibman
xibman3mo ago
for the locale fallback check this https://i18n.nuxtjs.org/docs/guide/locale-fallback
@nuxtjs/i18n
Locale fallback
How a fallback gets selected when a translation is missing.
Inès
Inès3mo ago
@xibman Actually the locale fallback works well for display, I have all messages displayed in english... BUT the thing is, when I print the value of useI18n().locale it displays en-US if I am on http://localhost:3002 which bothers me because I would really like it to be simply en
xibman
xibman3mo ago
{ code: 'en-US', domain: 'http://localhost:3002/' }, change it by { code: 'en', domain: 'http://localhost:3002/' },
Inès
Inès3mo ago
But if I do so, it won't work, it will still default to en-US for some reason
xibman
xibman3mo ago
clear your cookie
Inès
Inès3mo ago
I think what the nuxt config does is that it searches for the 1st code occurrence and matches it against its corresponding domain So 2 domains declared for the same code won't work I cleared the cookies but still (I didn't find any cookie saying en-US btw) (that's my conclusion after so many hours spent on this issue, but not sure about it)
xibman
xibman3mo ago
Think you're right !
Inès
Inès3mo ago
I was hoping I wouldn't be right 😂 The question that remains, still, is, how to overwrite this en-US default to force it to something else...
xibman
xibman3mo ago
do you have a default language set in your config ? do you use the cookie config ?
Inès
Inès3mo ago
As per the cookie config I don't think I have something like that set no, I put all my i18n-related config in my first post I think that's it I only set a fallbackLocale, not a defaultLocale... Thanks a lot @xibman! Regarding the initial reason of this post, I will open an issue in the i18n module directly so that one locale can point to several domains Thanks!
Want results from more Discord servers?
Add your server