NuxtN
Nuxt13mo ago
4 replies
Zyme

Detecting locale using env variables not working

I am trying to get my multi domain locale detection working but it isn't.
I don't want to use a prefix, it is different domains and I want to try out the translation in dev.

I have:
nuxt.config.ts
const i18nDomains = ["mydomain.com", "mydomain.se"] as any;

...

i18n: {
    vueI18n: "./i18n.config.ts",
    multiDomainLocales: true,
    lazy: true, // Lazy load translations
    strategy: "no_prefix", // No prefix like "en" or "se" in routes
    locales: [
      {
        code: "en",
        domains: i18nDomains,
        name: "English",
        defaultForDomains: ["mydomain.com"],
      },
      {
        code: "se",
        domains: i18nDomains,
        name: "Svenska",
        defaultForDomains: ["mydomain.se"],
      },
    ],
  },


Then I set the local using Powershell:
$env:DOMAIN_SE="mydomain.se" && npm run dev

But it loads the english website and is looking for keys in the "en" locale:
[intlify] Not found 'Hello' key in 'en' locale messages

And yes, this is true, it does not exist in "en" because "en" is the default language:
{{ $t("Hello") }}


So how do I make it look in the "se" locale?

And if the language is "en" I don't want to see this error message.
I don't want to translate english to english. I want to use the full strings in the code instead of using translation keys.

Lastly I need this to work with the generate command. So that I can get a translated website in static format in different languages.
Was this page helpful?