如果VueI18n没有找到它,它是否有可能退回到较短的键。
例如,我有以下信息:
{
en: {
"hello": "This is the fallback message!",
"admin.hello": "This is some other message for another context"
}
}下面的代码说明了结果应该是什么:
{{ $t("does.not.exists.hello") }} // should fallback on hello, so the result will be "This is the fallback message!"
{{ $t("admin.hello") }} // Message exists so the result should be "This is some other message for another context"
{{ $t("hello") }} // Message exists so the result should be "This is the fallback message!"发布于 2018-12-30 19:34:31
好吧,这个问题,我本来想快点的。MissingHandler对此非常有用。
代码示例如下所示: Vue.use(VueI18n)
//创建带有选项的VueI18n实例
export default new VueI18n({
locale: 'en', // set locale
silentTranslationWarn: true,
missing: (locale: Locale, key: Path, vm?: Vue) => {
if(key.includes(".")) {
let newKey = /\.(.+)/.exec(key)[1];
console.log(newKey)
return vm.$t(newKey) as string
}
return key
},
//formatter: new CustomFormatter(),
fallbackLocale: 'en',
messages // set locale messages
})https://stackoverflow.com/questions/53980750
复制相似问题