Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nuxt-i18n Strategy:no_prefix

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

like image 571
Surya Chandra Rao Gandreddi Avatar asked Oct 20 '25 15:10

Surya Chandra Rao Gandreddi


1 Answers

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)

like image 129
praburangki Avatar answered Oct 22 '25 04:10

praburangki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!