|
|
@ -3,6 +3,24 @@ function updateContent() {
|
|
|
|
$('body').localize();
|
|
|
|
$('body').localize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const defaultLanguage = 'en';
|
|
|
|
const defaultLanguage = 'en';
|
|
|
|
|
|
|
|
const LANGUAGES = {
|
|
|
|
|
|
|
|
'ca': 'Català',
|
|
|
|
|
|
|
|
'de': 'Deutsch',
|
|
|
|
|
|
|
|
'en': 'English',
|
|
|
|
|
|
|
|
'es': 'Español',
|
|
|
|
|
|
|
|
'fr': 'Français',
|
|
|
|
|
|
|
|
'hu': 'magyar',
|
|
|
|
|
|
|
|
'it': 'Italiano',
|
|
|
|
|
|
|
|
'ja': '日本語',
|
|
|
|
|
|
|
|
'ko': '한국어',
|
|
|
|
|
|
|
|
'nl': 'Nederlands',
|
|
|
|
|
|
|
|
'pl': 'Polski',
|
|
|
|
|
|
|
|
'pt-BR': 'Português',
|
|
|
|
|
|
|
|
'ru': 'Русский',
|
|
|
|
|
|
|
|
'th': 'ไทย',
|
|
|
|
|
|
|
|
'zh-CN': '简体中文',
|
|
|
|
|
|
|
|
'zh-TW': '繁體中文'
|
|
|
|
|
|
|
|
};
|
|
|
|
i18next
|
|
|
|
i18next
|
|
|
|
.use(i18nextXHRBackend)
|
|
|
|
.use(i18nextXHRBackend)
|
|
|
|
.use(i18nextBrowserLanguageDetector)
|
|
|
|
.use(i18nextBrowserLanguageDetector)
|
|
|
@ -13,30 +31,16 @@ i18next
|
|
|
|
loadPath: 'locales/{{lng}}.json',
|
|
|
|
loadPath: 'locales/{{lng}}.json',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, (err, t) => {
|
|
|
|
}, (err, t) => {
|
|
|
|
const languages = [
|
|
|
|
|
|
|
|
['ca', 'Català'],
|
|
|
|
|
|
|
|
['de', 'Deutsch'],
|
|
|
|
|
|
|
|
['en', 'English'],
|
|
|
|
|
|
|
|
['es-ES', 'Español'],
|
|
|
|
|
|
|
|
['fr', 'Français'],
|
|
|
|
|
|
|
|
['hu', 'magyar'],
|
|
|
|
|
|
|
|
['it', 'Italiano'],
|
|
|
|
|
|
|
|
['ja', '日本語'],
|
|
|
|
|
|
|
|
['ko', '한국어'],
|
|
|
|
|
|
|
|
['nl', 'Nederlands'],
|
|
|
|
|
|
|
|
['pt-BR', 'Português'],
|
|
|
|
|
|
|
|
['ru', 'Русский'],
|
|
|
|
|
|
|
|
['zh-CN', '简体中文'],
|
|
|
|
|
|
|
|
['zh-TW', '繁體中文'],
|
|
|
|
|
|
|
|
['th-TH', 'ไทย'],
|
|
|
|
|
|
|
|
['pl', 'Polski'],
|
|
|
|
|
|
|
|
].sort(),
|
|
|
|
|
|
|
|
languageSelector = $('#language');
|
|
|
|
languageSelector = $('#language');
|
|
|
|
languages.map(([code, name]) => {
|
|
|
|
for (let [code, name] of Object.entries(LANGUAGES)) {
|
|
|
|
languageSelector.append(`<option value="${code}"${code == i18next.language ? ' selected' : ''}>${name}</option>`);
|
|
|
|
languageSelector.append(`<option value="${code}">${name}</option>`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (!languageSelector.find('[selected]').length)
|
|
|
|
for (let code of i18next.languages) {
|
|
|
|
languageSelector.val(defaultLanguage);
|
|
|
|
if (code in LANGUAGES) {
|
|
|
|
|
|
|
|
languageSelector.val(code);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
languageSelector.on('change', function () {
|
|
|
|
languageSelector.on('change', function () {
|
|
|
|
if (this.value == i18next.language)
|
|
|
|
if (this.value == i18next.language)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -44,11 +48,6 @@ i18next
|
|
|
|
});
|
|
|
|
});
|
|
|
|
jqueryI18next.init(i18next, $);
|
|
|
|
jqueryI18next.init(i18next, $);
|
|
|
|
i18next.on('languageChanged', lng => {
|
|
|
|
i18next.on('languageChanged', lng => {
|
|
|
|
if (!languageSelector.find(`[value=${lng}]`).length) {
|
|
|
|
|
|
|
|
i18next.changeLanguage(defaultLanguage);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
languageSelector.val(lng);
|
|
|
|
|
|
|
|
updateContent();
|
|
|
|
updateContent();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// init set content
|
|
|
|
// init set content
|
|
|
|