VUE i18n not able to translate error messages

1.2k views Asked by At

I have added the VUE i18n module to handle the translations locally and it is working fine. Now I want to translate the error messages which I'm receiving from the backend. My configurations are

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()
 })

I'm hitting an API and able to translate the message in the response of that API. Can anyone help me in this. Thanks

0

There are 0 answers