nuxt-i18n策略:no_prefix

时间:2020-03-19 14:14:54

标签: nuxt.js vue-i18n nuxt-i18n

我正在尝试使用nuxt-i18n来实现我的应用程序的国际化,以下是nuxt-i18n的配置,它可以正常工作,但是当我要使用策略时:'no_prefix'它给出了错误信息……不是确定该怎么做,请提出建议。

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]将非当前语言环境传递给switchLocalePath是 使用no_prefix策略时不受支持
19:39:39

WARN [nuxt-i18n]将非当前语言环境传递给localePath是 使用no_prefix策略时不受支持
19:39:39

1 个答案:

答案 0 :(得分:4)

如果您使用no_prefix策略,则无法使用模块提供的path功能。例如,使用switchLocalePath时不支持那些2 localePathno_prefix。正如文档所说:

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

因此,您应该使用模块提供的API来更改语言环境。我的项目中的一个示例是,当用户想要更改语言环境时,我添加了一个处理程序并通过调用此命令来更改语言环境:

this.$i18n.setLocale('en')

root.$i18n.setLocale(langCode)(如果使用composition-api)