i18n: Cannot read property 'iso' of undefined

IMPORTANT: Please use the following link to create a new issue:

https://nuxtjs.cmty.io/issues/new?repo=nuxt-community%2Fnuxt-i18n

If your issue was not created using the app above, it will be closed immediately.

^ I am not handing this site a token for my github account.

i’m getting the error

Cannot read property 'iso' of undefined

i’d like to know which iso you are using there is es of the iso and es-ES

soooooo which is it.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15

Commits related to this issue

Most upvoted comments

I’ve looked a bit at the code.

With default strategy (prefix_except_default), with two pages: index.vue and about.vue, these routes are generated:

    routes: [{
      path: "/en/about",
      component: _33ee994b,
      name: "about___en"
    }, {
      path: "/jp/about",
      component: _33ee994b,
      name: "about___jp"
    }, {
      path: "/en/",
      component: _53a67410,
      name: "index___en"
    }, {
      path: "/jp/",
      component: _53a67410,
      name: "index___jp"
    }],

As there is no /about route being generated, the whole redirection logic fails because it can only redirect from existing routes due to needing route’s name to properly resolve current route and route to redirect to.

The behavior is slightly different whether it’s first redirect in the app or subsequent. On first it will redirect from unknown route to index. After that, when cookie is already set, it will just fail with error above (unless alwaysRedirect: true I guess).

It’s IMO also buggy that on first redirect it will redirect to index. It should probably just trigger 404 if it can’t figure out which route to redirect to.

One way to fix it would potentially be to add code to resolve route by path. If user visits non-existing route like /about, we would add defaultLocale prefix and try to resolve by path. But then when user visits /xx/about, maybe we should strip the ‘xx’ prefix and then add default locale. Not sure how smart it would need to be.

BTW. The root issue seems to stem from bad redirection logic but it would be easy to foolproof the code that is failing (in seo-head.js) to not fail in this case.

@begueradj You probably missed to encapsulate the module in an array. You can find more details on the issue here: https://github.com/nuxt-community/google-adsense-module/issues/13#issuecomment-397820366

@paulgv I am getting the same error and I am using the config straight out of the docs:

['nuxt-i18n', {
      locales: ['en', 'fr', 'es'],
      defaultLocale: 'en',
      vueI18n: {
        fallbackLocale: 'en',
        messages: {
          en: {
            welcome: 'Welcome'
          },
          fr: {
            welcome: 'Bienvenue'
          },
          es: {
            welcome: 'Bienvenido'
          }
        }
      }
    }]

Hey @paulgv thanks so much for the reply, unfortunately, I’m working on a time-sensitive project. So I’ve now gone with just using vue and rolling my own boilerplate. As such i’ve removed the config and i didnt commit a version of it so its not in my git history.

If i get some time spare i shall try to replicate the issue.