Commit aebbd675 authored by Richard Blechinger's avatar Richard Blechinger
Browse files

Add i18n module to enable translations

parent cae7bd40
This diff is collapsed.
...@@ -46,16 +46,21 @@ ...@@ -46,16 +46,21 @@
</b-nav-item> </b-nav-item>
</b-navbar-nav> </b-navbar-nav>
<b-navbar-nav class="ml-auto"> <b-navbar-nav class="ml-auto">
<b-nav-item>
{{ $t('helloWorld') }}
</b-nav-item>
<b-nav-item-dropdown <b-nav-item-dropdown
text="EN" :text="$activeLocale.toUpperCase()"
right right
> >
<b-dropdown-item href="#"> <b-dropdown-item :active="$activeLocale === 'de'" @click="$locale('de')">
EN
</b-dropdown-item>
<b-dropdown-item href="#">
DE DE
</b-dropdown-item> </b-dropdown-item>
<b-dropdown-item :active="$activeLocale === 'en'" @click="$locale('en')">
EN
</b-dropdown-item>
</b-nav-item-dropdown> </b-nav-item-dropdown>
<b-nav-item-dropdown <b-nav-item-dropdown
v-if="user.logged_in" v-if="user.logged_in"
......
export default {
'helloWorld': 'Hallo, Welt'
}
export default {
'helloWorld': 'Hello, World'
}
...@@ -2,8 +2,11 @@ import Vue from 'vue' ...@@ -2,8 +2,11 @@ import Vue from 'vue'
import App from './App.vue' import App from './App.vue'
import router from './router' import router from './router'
import store from './store' import store from './store'
import Translation from '@/plugins/translation';
import BootstrapVue from 'bootstrap-vue' import BootstrapVue from 'bootstrap-vue'
import VueLogger from 'vuejs-logger'; import VueLogger from 'vuejs-logger';
import '../public/assets/tailwind.css' import '../public/assets/tailwind.css'
// Use this if you also have to debug a production build // Use this if you also have to debug a production build
...@@ -21,6 +24,7 @@ Vue.use(VueLogger, { ...@@ -21,6 +24,7 @@ Vue.use(VueLogger, {
}); });
Vue.use(BootstrapVue) Vue.use(BootstrapVue)
Vue.use(Translation)
Vue.config.productionTip = false Vue.config.productionTip = false
......
import Polyglot from 'node-polyglot';
const Translation = {}
Translation.install = async function(Vue) {
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
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
this.$activeLocale = newLocale
this.polyglot = new Polyglot({ phrases })
this.$forceUpdate()
}
};
export default Translation
...@@ -343,8 +343,13 @@ const actions = { ...@@ -343,8 +343,13 @@ const actions = {
let method = data.update ? 'put' : 'post' let method = data.update ? 'put' : 'post'
let formData = new FormData(); let formData = new FormData();
// We serialize the data to a FormData object, so we can send the image
// as binary blob to the Steering API.
for (const [key, value] of Object.entries(data.note)) { for (const [key, value] of Object.entries(data.note)) {
if (data.update && NON_UPDATEABLE_PROPERTIES.includes(key)) continue; // When we're updating we don't want to include some properties that cause errors.
if (data.update && NON_UPDATEABLE_PROPERTIES.includes(key)) {
continue;
}
formData.append(key, value); formData.append(key, value);
} }
......
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