Skip to content

Commit

Permalink
Import the i18n files so they are compiled with Webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Nov 18, 2018
1 parent e70747e commit 4fc6850
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .tx/config
Expand Up @@ -2,9 +2,9 @@
host = https://www.transifex.com

[contao-manager.ui]
source_file = src/assets/i18n/en.json
source_file = src/i18n/en.json
source_lang = en
file_filter = src/assets/i18n/<lang>.json
file_filter = src/i18n/<lang>.json
type = KEYVALUEJSON

[contao-manager.api]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions public/i18n/en.json → src/i18n/en.json
Expand Up @@ -118,6 +118,7 @@
"ui.taskpopup.buttonClose": "Close",
"ui.taskpopup.buttonConfirm": "Confirm & Close",
"ui.taskpopup.buttonCancel": "Cancel",
"ui.taskpopup.buttonAborting": "Aborting …",
"ui.taskpopup.console": "Show/Hide Console Output",
"ui.taskpopup.noconsole": "Waiting for console output …",
"ui.taskpopup.autoclose": "Close the task when successful",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 29 additions & 19 deletions src/i18n/index.js
Expand Up @@ -3,17 +3,25 @@ import Vue from 'vue';
import vuexI18n from 'vuex-i18n';

import store from '../store';
import locales from './locales';

import fallback from '../../public/i18n/en.json';

Vue.use(vuexI18n.plugin, store);

Vue.i18n.add('en', fallback);
Vue.i18n.set('en');
Vue.i18n.fallback('en');
const locales = {
en: () => import('./en.json'),
de: () => import('./de.json'),
br: () => import('./br.json'),
cs: () => import('./cs.json'),
es: () => import('./es.json'),
fa: () => import('./fa.json'),
fr: () => import('./fr.json'),
ja: () => import('./ja.json'),
lv: () => import('./lv.json'),
nl: () => import('./nl.json'),
pl: () => import('./pl.json'),
ru: () => import('./ru.json'),
sr: () => import('./sr.json'),
zh: () => import('./zh.json'),
};

export default {
const i18n = {
init() {
let userLang = window.localStorage.getItem('contao_manager_locale');

Expand All @@ -24,28 +32,30 @@ export default {
return this.load(userLang);
},

load(locale) {
async load(locale) {
window.localStorage.setItem('contao_manager_locale', locale);

if (Vue.i18n.localeExists(locale)) {
Vue.i18n.set(locale);
return new Promise(resolve => resolve());
return;
}

if (!locales[locale]) {
if (locale.length === 5) {
return this.load(locale.slice(0, 2));
}

return new Promise((resolve, reject) => reject());
throw `Locale ${locale} does not exist.`;
}

return Vue.http.get(`i18n/${locale}.json`).then(
response => response.json().then((json) => {
Vue.i18n.add(locale, json);
Vue.i18n.set(locale);
}),
() => {},
);
Vue.i18n.add(locale, Object.assign({}, await locales[locale]()));
Vue.i18n.set(locale);
},
};


Vue.use(vuexI18n.plugin, store);
Vue.i18n.fallback('en');
i18n.load('en');

export default i18n;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4fc6850

Please sign in to comment.