From ac0d6b1bf5833536b28aabad25b628ea0322fb76 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 6 Aug 2017 21:37:47 +1200 Subject: Fallback to default language --- web/load.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'web') diff --git a/web/load.js b/web/load.js index 568a4bf8..86b98290 100644 --- a/web/load.js +++ b/web/load.js @@ -1,5 +1,5 @@ (function () { - var debugMode, touchMode, locale, localeParameter, extjsVersion, proj4jsVersion, fontAwesomeVersion, olVersion, i, language, languages; + var debugMode, touchMode, locale, localeParameter, extjsVersion, proj4jsVersion, fontAwesomeVersion, olVersion, i, language, languages, languageDefault; function addStyleFile(file) { var link = document.createElement('link'); @@ -83,6 +83,7 @@ 'zh_TW': { name: '中文 (Taiwan)', code: 'zh_TW' } }; + languageDefault = 'en'; localeParameter = window.location.search.match(/locale=([^&#]+)/); locale.language = localeParameter && localeParameter[1]; if (!(locale.language in locale.languages)) { @@ -90,7 +91,7 @@ language = window.navigator.userLanguage || window.navigator.language; languages.push(language); languages.push(language.substr(0, 2)); - languages.push('en'); //default + languages.push(languageDefault); for (i = 0; i < languages.length; i++) { language = languages[i].replace('-', '_'); if (language in locale.languages) { @@ -109,14 +110,24 @@ } Ext.Ajax.request({ - url: 'l10n/' + Locale.language + '.json', + url: 'l10n/' + languageDefault + '.json', callback: function (options, success, response) { window.Strings = Ext.decode(response.responseText); - - if (debugMode) { - addScriptFile('app.js'); - } else { - addScriptFile('app.min.js'); + if (Locale.language !== languageDefault) { + Ext.Ajax.request({ + url: 'l10n/' + Locale.language + '.json', + callback: function (options, success, response) { + var key, data = Ext.decode(response.responseText); + for (key in data) { + if (data.hasOwnProperty(key)) { + window.Strings[key] = data[key]; + } + } + addScriptFile(debugMode ? 'app.js' : 'app.min.js'); + } + }); + } else { + addScriptFile(debugMode ? 'app.js' : 'app.min.js'); } } }); -- cgit v1.2.3