diff --git a/js/translations.js b/js/translations.js index d4f0393..ef560e3 100644 --- a/js/translations.js +++ b/js/translations.js @@ -3,6 +3,24 @@ function updateContent() { $('body').localize(); } 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 .use(i18nextXHRBackend) .use(i18nextBrowserLanguageDetector) @@ -13,30 +31,16 @@ i18next loadPath: 'locales/{{lng}}.json', }, }, (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'); - languages.map(([code, name]) => { - languageSelector.append(``); - }); - if (!languageSelector.find('[selected]').length) - languageSelector.val(defaultLanguage); + for (let [code, name] of Object.entries(LANGUAGES)) { + languageSelector.append(``); + } + for (let code of i18next.languages) { + if (code in LANGUAGES) { + languageSelector.val(code); + break; + } + } languageSelector.on('change', function () { if (this.value == i18next.language) return; @@ -44,11 +48,6 @@ i18next }); jqueryI18next.init(i18next, $); i18next.on('languageChanged', lng => { - if (!languageSelector.find(`[value=${lng}]`).length) { - i18next.changeLanguage(defaultLanguage); - return; - } - languageSelector.val(lng); updateContent(); }); // init set content