VUE i18n无法翻译错误消息

问题描述

添加了VUE i18n模块来本地处理翻译,并且工作正常。现在,我要翻译从后端收到的错误消息。 我的配置是

import Vue from 'vue'
import VueI18n from 'vue-i18n'

Vue.use(VueI18n)

function loadLocaleMessages () {
const locales = require.context('./locales',true,/[A-Za-z0-9-_,\s]+\.json$/i)
const messages = {}
locales.keys().forEach(key => {
const matched = key.match(/([A-Za-z0-9-_]+)\./i)
if (matched && matched.length > 1) {
  const locale = matched[1]
  messages[locale] = locales(key)
}
})
return messages
}

export default new VueI18n({
 locale: process.env.VUE_APP_I18N_LOCALE || 'en-GB',fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en-GB',messages: loadLocaleMessages()
 })

我正在点击一个API,并且能够在该API的响应中转换消息。谁能帮我这个忙。谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)