【问题标题】:How to show the english translation, if you didn’t find the translate in the selected language file?如果在所选语言文件中没有找到翻译,如何显示英文翻译?
【发布时间】:2020-05-06 07:52:44
【问题描述】:

我有两个语言环境:ru、en。

如果在所选语言文件中没有找到翻译,如何显示英文翻译?

我的 i18n 设置:

  i18n: {
    defaultLocale: 'en',
    fallbackLocale: 'en',
    strategy: 'no_prefix',
    locales: [
      {
        code: 'ru',
        name: 'Russian',
        file: 'ru-RU.js'
      },
      {
        code: 'en',
        name: 'English',
        file: 'en-US.js'
      }
    ],
    detectBrowserLanguage: {
      useCookie: false,
    },
    differentDomains: false,
    forwardedHost: false,
    lazy: true,
    langDir: 'lang/',
    parsePages: false,
  },

目前在json文件中显示带有字段名的字符串。

【问题讨论】:

  • 您在 url 中使用了与当前活动语言匹配的任何变量?如果是,您可以根据 url 参数更改文本

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


【解决方案1】:

在所需的页面或组件中,您可以在创建的生命周期内调用它为:

created() {
  this.$router.replace(this.switchLocalePath('en'));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 2022-12-09
    • 1970-01-01
    相关资源
    最近更新 更多