nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.74k stars 480 forks source link

Locale ISO code is required to generate alternate link #2836

Closed kaboume closed 8 months ago

kaboume commented 8 months ago

Environment


Reproduction

nuxt.config.js :

i18n: {
    vueI18n: "./i18n.config.ts",
    locales: ["en", "fr"], 
    defaultLocale: "fr", 
    customRoutes: "config", // disable custom route with page components
    pages: {
      index: {
        fr: "/",
        en: "/",
      },
      contact: {
        fr: "/contact",
        en: "/contact",
      },
      "formations/[uid]": {
        fr: "/formation/[uid]",
        en: "/training/[uid]",
      },

Describe the bug

I use useSetI18nParams because I have Dynamic route parameters. Here is my page tree: /pages/training/[uid].view

In my page /pages/formations/[uid].vue, I have:

<script setup>
const setI18nParams = useSetI18nParams();

const { data, pending, error } = await useLazyAsyncData(async () => {
      ....
       setI18nParams({
         en: { uid: tabUrlsLanguage.get("en") },
         fr: { uid: tabUrlsLanguage.get("fr") },
       });
     }
   }

When the switchLocalePath() is executed, the page laughs refreshing with this message in the log:

Locale ISO code is required to generate alternate link

Additional context

No response

Logs

No response

BobbieGoede commented 8 months ago

You should configure your locales as objects with an iso property, see https://i18n.nuxtjs.org/docs/guide/seo#requirements for an example. Let me know if that resolves the issue for you.

kaboume commented 8 months ago

Thanks, it works !