Robert Strauch
Robert Strauch

Reputation: 12876

Dynamic loading of translations during runtime in VueJS and VueI18n

We're using the 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.

However there is a major drawback in our current approach. We're pulling the translations from Zanata during build time, i.e. "baking" them into the application. As a consequence, we need to rebuild and redeploy the application each time a text is edited.

Are there any approaches which pull the translations (or the translation files) when running the application so that the user is always presented the latest content?

Upvotes: 3

Views: 1780

Answers (1)

Radu Diță
Radu Diță

Reputation: 14171

You should be able to do this if you load the translation file and then use setLocaleMessage( locale, message ) to load them. I'm assuming you're using axios.

axios.get('/path/to/locale_de')
.then((response) => {
  Vuei18nInstance.setLocaleMessage('de', response)
});

The response should be a plain JSON.

Upvotes: 3

Related Questions