【问题标题】:Nuxt i18n does not load cookie language in root directoryNuxt i18n 不在根目录中加载 cookie 语言
【发布时间】:2020-08-04 08:11:21
【问题描述】:

每当我在应用程序中选择一种语言时,它都会将此参数保存在“lang”cookie 中,但在没有语言路径 (http://localhost/en) 的情况下访问根目录 (http://localhost) 时会加载默认语言“pt”,甚至以另一种语言“en”或“es”设置的 cookie。这个是正常的?或者这种情况有什么配置吗?

[
  'nuxt-i18n',
  {
    locales: [
      {
        code: 'en',
        file: 'en.js'
      },
      {
        code: 'es',
        file: 'es.js'
      },
      {
        code: 'pt',
        file: 'pt.js'
      }
    ],
    lazy: true,
    langDir: 'lang/',
    parsePages: false,
    strategy: 'prefix',
    defaultLocale: 'pt',
    rootRedirect: 'pt',
    detectBrowserLanguage: {
      useCookie: true,
      cookieDomain: null,
      cookieKey: 'lang',
      alwaysRedirect: false,
      fallbackLocale: 'pt'
    },
  }
]

方法更改语言:

changeLanguage(lang) {
        this.locale = lang
        this.$i18n.setLocale(lang)
        this.$moment.locale(lang);
    },

【问题讨论】:

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


    【解决方案1】:

    我发现我需要将 alwaysRedirect 参数设置为 true,它会通过 cookie 强制重定向。

    detectBrowserLanguage: {
      alwaysRedirect: true
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-06
      • 2021-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-29
      • 2022-10-24
      • 2021-07-31
      相关资源
      最近更新 更多