Skip to content
Snippets Groups Projects
Commit 63f7e2d3 authored by Richard Blechinger's avatar Richard Blechinger
Browse files

Fix issue caused by async plugin installation

parent 2618902e
No related branches found
No related tags found
No related merge requests found
import Polyglot from 'node-polyglot';
const Translation = {}
Translation.install = async function(Vue) {
Vue.prototype.getPhrasesForLocale = async (locale) => {
const phrasesModule = await import(`@/i18n/${locale}`)
return phrasesModule.default
}
import de from '@/i18n/de'
import en from '@/i18n/en'
const availableLocales = [ 'de', 'en' ]
const Translation = {}
Translation.install = function(Vue) {
const availableLocales = { de, en };
const potentialLocale = navigator.language.substring(0, 2)
const activeLocale = availableLocales.includes(potentialLocale)
? potentialLocale
: 'de'
const phrases = await Vue.prototype.getPhrasesForLocale(activeLocale);
const activeLocale = availableLocales.hasOwnProperty(potentialLocale) ? potentialLocale : 'de'
const phrases = availableLocales[activeLocale];
Vue.prototype.$activeLocale = activeLocale
Vue.prototype.polyglot = new Polyglot({ phrases })
Vue.prototype.$t = function(text, context = {}) {
return this.polyglot.t(text, context)
}
Vue.prototype.$activeLocale = activeLocale
Vue.prototype.getPhrasesForLocale = (locale) => availableLocales[locale];
Vue.prototype.$locale = async function(newLocale) {
const phrases = await this.getPhrasesForLocale(newLocale)
Vue.prototype.$locale = function(newLocale) {
const phrases = this.getPhrasesForLocale(newLocale)
this.$activeLocale = newLocale
this.polyglot = new Polyglot({ phrases })
this.$forceUpdate()
}
Vue.prototype.$t = function(text, context = {}) {
return this.polyglot.t(text, context)
}
};
export default Translation
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment