Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
VueI18n locale message loading issue

I have the vueI18n package installed for language localization in the app and the locale messages object is fetched through an api call. I have config file where the default language is specified and based on which the locale will be loaded before the app.vue is created. ie; I'm loading the locale in beforeCreate lifecycle method. But still the text are not loaded properly.

Initially the message object is null because based on the user config we are fetching the language and loading the messages. I am assuming the initial empty object is causing the issue.

Could someone suggest a way we can delay the page load until we confirm the message object is loaded successfully.

vueI18 config file

import Vue from 'vue'
import VueI18n from 'vue-i18n'
import userConfig from './userConfig'
import apiService from '@/service/apiService.js'

let selectedLanguage = ''
Vue.use(VueI18n)

const loadLocaleMessages = async (lang) => {
  const messages = await apiService.getLocale(lang)
  return messages
}

export const i18n = new VueI18n({
  locale: selectedLanguage,
  fallbackLocale: userConfig.defaultLocalizationKey,
  formatFallbackMessages: true,
  messages: {}
})

export const loadLanguage = async lang => {
  const messages = await loadLocaleMessages(lang)
  selectedLanguage = lang
  return i18n.setLocaleMessage(selectedLanguage, messages[lang])
}

App.vue

  async beforeCreate () {
    await loadLanguage(this.$userConfig.defaultLocalizationKey)
    this.$i18n.locale = this.$userConfig.defaultLocalizationKey
  }
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

The good practice is to always have a default/fallback language inside vue-i18n, e.g. English. If you can't do this for whatever reason, then you can simply put a v-if on the App's template so that nothing is rendered until you fetch at least 1 language into vue-i18n.

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda