4

I'm trying to use nuxt-i18n to get internationalization for my application, the following are the nuxt-i18n configs and it works fine, but when I want to use strategy: 'no_prefix' it gives errors ... not sure what to do, please suggest.

i18n: {
    //strategy: 'no_prefix',
    defaultLocale: 'en',
    locales: [
      {
        code: 'en',
        name: 'English',
        iso: 'en-US',
        file: 'english.js'
      },
      {
        code: 'hi',
        name: 'Hindi',
        file: 'hindi.js'
      }
    ],
    lazy: true,
    langDir: 'static/locales/'
  },

https://nuxt-community.github.io/nuxt-i18n/routing.html#strategy

WARN [nuxt-i18n] Passing non-current locale to switchLocalePath is unsupported when using no_prefix strategy
19:39:39

WARN [nuxt-i18n] Passing non-current locale to localePath is unsupported when using no_prefix strategy
19:39:39

1 Answers1

8

If you are using the no_prefix strategy you won't get the benefit for using the path functions that is provided by the module. For example those 2 switchLocalePath & localePath is not supported when using no_prefix. As the docs say:

This implies that you have to rely on browser & cookie detection, and implement locale switches by calling the i18n API.

So you should use the APIs that are provided by the module in order to change the locale. One of example in my project is when user want's to change a locale I added a handler and change the locale by calling this:

this.$i18n.setLocale('en')

or

root.$i18n.setLocale(langCode) (if using the composition-api)

praburangki
  • 135
  • 2
  • 9