vue-i18n 日期本地化未本地化
vue-i18n date localization not localizing
我有一个使用 vue-i18n 本地化的应用程序。所有字符串都保存在 JSON 文件中,并且翻译有效。现在我需要添加一个日期时间本地化 as seen here 但该模块没有选择我的配置,我在控制台中收到有关 "Fall back to 'en-US' datetime formats from 'en datetime formats."
的警告
配置
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
我一直收到相同的警告,但我的标记中没有打印任何内容
一切都按预期进行。看看下面的片段。
也许您的问题来自其他地方?
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>
我有一个使用 vue-i18n 本地化的应用程序。所有字符串都保存在 JSON 文件中,并且翻译有效。现在我需要添加一个日期时间本地化 as seen here 但该模块没有选择我的配置,我在控制台中收到有关 "Fall back to 'en-US' datetime formats from 'en datetime formats."
的警告配置
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
我一直收到相同的警告,但我的标记中没有打印任何内容
一切都按预期进行。看看下面的片段。
也许您的问题来自其他地方?
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>