nuxt.js - nuxt-i18n 策略 :no_prefix

标签 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] 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

最佳答案

如果您使用 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)

关于nuxt.js - nuxt-i18n 策略 :no_prefix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60758974/

相关文章:

node.js - Nuxt run dev fatal error ,状态码 500

javascript - 如何使我的 NuxtJS 过渡布局特定而不是全局?

javascript - 组件内 Navigation Guard 回调不起作用 : Nuxt JS and `beforeRouteEnter`

vue.js - 如何在组件属性/property中使用Vue I18n翻译

javascript - vue组件中访问i18n.locales并动态更改其值的问题

javascript - Nuxt-i18n:如何异步加载消息?

css - 如何调整 vuetify 组件中的分隔线宽度?

javascript - Vue.js 3 - 在 vue 中使用 Vue I18n 插件时出错 - 无法设置未定义的属性 '_vm'

javascript - 在哪里执行方法来保存 nuxt-i18n 中的语言环境更改?

javascript - 从 nuxt.js 中间件获取语言