Commit 2618902e authored by Richard Blechinger's avatar Richard Blechinger
Browse files

Reduce code duplication

parent aebbd675
......@@ -2,27 +2,27 @@ 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
}
const availableLocales = [ 'de', 'en' ]
const potentialLocale = navigator.language.substring(0, 2)
const activeLocale = availableLocales.includes(potentialLocale)
? potentialLocale
: 'de'
const phrasesModule = await import(`@/i18n/${activeLocale}`)
const phrases = phrasesModule.default
const phrases = await Vue.prototype.getPhrasesForLocale(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.$locale = async function(newLocale) {
this.$log.debug(`Setting locale: ${newLocale}`)
const phrasesModule = await import(`@/i18n/${newLocale}`)
const phrases = phrasesModule.default
const phrases = await this.getPhrasesForLocale(newLocale)
this.$activeLocale = newLocale
this.polyglot = new Polyglot({ phrases })
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment