nuxt.jsnuxt3.jsvue-i18nnuxt-i18n

i18n is not working after update nuxt to 3.8.0


after I updated my nuxt framework to 3.8.0 and updated my i18n library to 8.0.0. and I added it to the module in "nuxt.config.ts"

  modules: ['@nuxtjs/i18n'],

after I write i18n config in "nuxt.config.ts":

  i18n: {
locales: [
    {
        code: 'fa',
        iso: 'fa-IR',
        name: 'Farsi',
        file: 'fa-IR.json',
        dir: 'rtl',
    },
    {
        code: 'en',
        iso: 'en-US',
        name: 'English',
        file: 'en-US.json',
        dir: 'ltr',
    },
],
defaultLocale: 'fa',
detectBrowserLanguage: false,
langDir: "lang",
vueI18n: {
    legacy: false,
    fallbackLocale: 'en',
}

}

I got this error about i18n:

 ERROR  Cannot start nuxt:  input.includes is not a function   
at normalizeWindowsPath (node_modules/.pnpm/pathe@1.1.1/node_modules/pathe/dist/shared/pathe.92c04245.mjs:2:24)

and some other node-module errors.

any idea how can I fix this??


Solution

  • Okay, I can fix the problem first of all update your i18n dependency after that create a new file called i18n.config.ts in there, I write this code:

    export default defineI18nConfig(() => ({
    legacy: false,
    locale: 'en',
    messages: {
      en: {
        welcome: 'Welcome'
      },
      fr: {
        welcome: 'Bienvenue'
      }
    }}))
    

    At last, in nuxt.config.ts I called it

        i18n: {
        vueI18n: './i18n.config.ts'
    }
    

    you can check the i18n website to understand better structure of how it's work https://i18n.nuxtjs.org/