NuxtN
Nuxt2y ago
21 replies
melanie

i18n runtimeConfig different domains not working

Hi all,
in my Nuxt3 application, i have a lot of environment variables in my .env file and declare in my runtimeConfig. But when i use NUXT_PUBLIC_I18N_LOCALES_UK_DOMAIN to declare different domains in nuxt/i18n, it doesn't work. Here is my nuxt.config.ts:
export default defineNuxtConfig({
  devtools: { enabled: true },
  runtimeConfig: {
    public: {
      apiBase: process.env.NUXT_PUBLIC_API_BASE, // can be overridden by NUXT_PUBLIC_API_BASE environment variable
    },
    i18n: {
      locales: {
        uk: process.env.NUXT_PUBLIC_I18N_LOCALES_UK_DOMAIN,
        fr: process.env.NUXT_PUBLIC_I18N_LOCALES_FR_DOMAIN,
      },
    },
  },
  modules: ["@nuxtjs/i18n"],
  i18n: {
    locales: [
      {
        code: "uk",
        domain: process.env.NUXT_PUBLIC_I18N_LOCALES_UK_DOMAIN,
        file: "en.ts",
      },
      {
        code: "fr",
        domain: process.env.NUXT_PUBLIC_I18N_LOCALES_FR_DOMAIN,
        file: "fr.ts",
      },
    ],
    differentDomains: true,
    langDir: "lang",
  },
});


Here is my .env file:
NUXT_PUBLIC_API_BASE="API prod"
NUXT_PUBLIC_I18N_LOCALES_UK_DOMAIN=http://mydomain.uk
NUXT_PUBLIC_I18N_LOCALES_FR_DOMAIN=http://mydomain.fr


And i launch my app through npm script "set -a && source ./.env && set +a && node .output/server/index.mjs" (not sure the best way)
I have an apache to serve mydomain.uk and mydomain.fr (proxy to localhost:3000)

Do you have an idea why it's not working ? Thanks !
Was this page helpful?