我有一个使用vue-i18n本地化的应用程序。所有字符串都保存在JSON文件中,并且翻译有效。现在,我需要添加一个日期时间本地化as seen here,但是该模块无法使用我的配置,并且我在控制台中收到有关“从'en datetime格式退回到'en-US'日期时间格式”的警告。 / p>
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
})
模板
<b-col cols="7" lg="12"><p class="margin-0">{{ $d(new Date(), 'short') }}</p></b-col>
我尝试显式设置{{ $d(new Date(), 'short', 'en-US') }}
,我尝试仅通过dateTimeFormats
,但我仍然收到相同的警告,并且标记中没有任何内容
答案 0 :(得分:1)
一切正常。看看片段式波纹管。
也许您的问题来自其他地方?
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>