3

我正在尝试使用 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

警告 [nuxt-i18n] 使用 no_prefix 策略时,不支持将非当前语言环境传递给 switchLocalePath
19:39:39

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

4

1 回答 1

7

如果您正在使用该no_prefix策略,您将无法从使用path模块提供的功能中获益。例如那些 2 switchLocalePath&localePath在使用时不受支持no_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)(如果使用组合 API)

于 2020-05-29T01:19:20.033 回答