【问题标题】:vue-i18n date localization not localizingvue-i18n 日期本地化未本地化
【发布时间】:2019-09-04 18:02:50
【问题描述】:

我有一个使用 vue-i18n 本地化的应用程序。所有字符串都保存在 JSON 文件中,翻译工作正常。现在我需要添加一个日期时间本地化 as seen here,但该模块没有获取我的配置,并且我在控制台中收到有关“从 'en datetime 格式回退到 'en-US' datetime 格式”的警告。

配置

import messages from './messages.json'
const dateTimeFormats = {
  'en-US': {
    short: {
      year: 'numeric', month: 'short', day: 'numeric'
    }
  }
}

const i18n = new VueI18n({
  locale: 'en',
  messages,
  dateTimeFormats
})

模板

<b-col cols="7" lg="12"><p class="margin-0">{{ $d(new Date(), 'short') }}</p></b-col>

我尝试明确设置{{ $d(new Date(), 'short', 'en-US') }},我尝试只传递dateTimeFormats 我不断收到相同的警告,但我的标记中没有打印任何内容

【问题讨论】:

    标签: javascript vue.js vuejs2 internationalization vue-i18n


    【解决方案1】:

    一切都按预期进行。看看下面的 sn-p。
    也许您的问题来自其他地方?

    const dateTimeFormats = {
      'en-US': {
        short: {
          year: 'numeric', month: 'short', day: 'numeric'
        }
      }
    }
    const messages = {
      'en-US': {
        foo: 'bar'
      }
    }
    
    const i18n = new VueI18n({
      locale: 'en',
      messages,
      dateTimeFormats
    })
    
    new Vue({
      i18n
    }).$mount("#app");
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue-i18n/8.14.0/vue-i18n.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
    
    <div id="app">
      <p>{{ $d(new Date(), 'short') }}</p>
      <p>{{ $t('foo') }}</p>
    </div>

    【讨论】:

    • 您能同时使用dateTimeFormats 和消息对象进行字符串翻译吗?
    猜你喜欢
    • 2016-08-21
    • 2021-12-03
    • 1970-01-01
    • 2021-12-13
    • 2010-10-08
    • 2021-08-03
    • 2019-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多