简体   繁体   English

vue-i18n日期本地化未本地化

[英]vue-i18n date localization not localizing

I have an app that's localized with vue-i18n. 我有一个使用vue-i18n本地化的应用程序。 All the strings are saved in a JSON file and the translation works. 所有字符串都保存在JSON文件中,并且翻译有效。 Now I need to add a datetime localization as seen here but the module doesn't pick up my configuration and I get warnings in the console about "Fall back to 'en-US' datetime formats from 'en datetime formats." 现在,我需要添加一个日期时间本地化( 如此处所示),但是该模块无法使用我的配置,并且在控制台中收到有关“从'en datetime格式降到'en-US'日期时间格式”的警告。

config 配置

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

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

template 模板

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

I've tried explicitly setting {{ $d(new Date(), 'short', 'en-US') }} , I've tried only passing the dateTimeFormats I keep getting the same warning and nothing prints in my markup 我试过显式设置{{ $d(new Date(), 'short', 'en-US') }} ,我试过仅传递dateTimeFormats我一直收到相同的警告,并且标记中没有任何内容

Everything works like expected. 一切正常。 Take a look on the snippet bellow. 看看摘要式波纹管。
Maybe your problem come from elsewhere? 也许您的问题来自其他地方?

 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM