在 VueJS 和 VueI18n 中运行时动态加载翻译
Dynamic loading of translations during runtime in VueJS and VueI18n
我们正在使用 VueI18n plugin for internationalizing our Vue application which is working fine so far. Text contents are managed and translated by our editorial staff using Zanata。
然而,我们当前的方法存在一个主要缺陷。我们在构建期间从 Zanata 中提取翻译,即 "baking" 它们进入应用程序。因此,每次编辑文本时,我们都需要重建和重新部署应用程序。
是否有任何方法可以在 运行 应用程序时提取翻译(或翻译文件),以便始终向用户显示最新内容?
如果您加载翻译文件然后使用 setLocaleMessage( locale, message ) 加载它们,您应该能够做到这一点。我假设您使用的是 axios。
axios.get('/path/to/locale_de')
.then((response) => {
Vuei18nInstance.setLocaleMessage('de', response)
});
响应应该是简单的 JSON。
我们正在使用 VueI18n plugin for internationalizing our Vue application which is working fine so far. Text contents are managed and translated by our editorial staff using Zanata。
然而,我们当前的方法存在一个主要缺陷。我们在构建期间从 Zanata 中提取翻译,即 "baking" 它们进入应用程序。因此,每次编辑文本时,我们都需要重建和重新部署应用程序。
是否有任何方法可以在 运行 应用程序时提取翻译(或翻译文件),以便始终向用户显示最新内容?
如果您加载翻译文件然后使用 setLocaleMessage( locale, message ) 加载它们,您应该能够做到这一点。我假设您使用的是 axios。
axios.get('/path/to/locale_de')
.then((response) => {
Vuei18nInstance.setLocaleMessage('de', response)
});
响应应该是简单的 JSON。