diff --git a/README.md b/README.md index 9fba3820..7ba5f772 100755 --- a/README.md +++ b/README.md @@ -48,6 +48,9 @@ This adapter cannot be installed directly from github. Only from npm. ## Changelog +### 0.3.5 (2019-04-15) +* (yaming116) bugfix i18n + ### 0.3.4 (2019-02-04) * (janfromberlin) button widget did not handle primitive boolean commands * (matthiasgasser) fix time series query start date, adapted end date diff --git a/src/app/services/data.service.js b/src/app/services/data.service.js index 4f261743..c1ad3889 100644 --- a/src/app/services/data.service.js +++ b/src/app/services/data.service.js @@ -11,11 +11,11 @@ .value('OH2ServiceConfiguration', {}) .service('OH2StorageService', OH2StorageService); - IOBService.$inject = ['$rootScope', '$http', '$q', '$timeout', '$interval', '$filter', '$location', 'SpeechService']; + IOBService.$inject = ['$rootScope', '$http', '$q', '$timeout', '$interval', '$filter', '$location', 'SpeechService', '$translate']; var connectPromise = null; var connecting = false; - function IOBService($rootScope, $http, $q, $timeout, $interval, $filter, $location, SpeechService) { + function IOBService($rootScope, $http, $q, $timeout, $interval, $filter, $location, SpeechService, $translate) { this.getItem = getItem; this.getItems = getItems; this.getObjects = getObjects; @@ -178,18 +178,31 @@ } else { connect().then(function () { servConn.getConfig(function (err, data) { + var language; + if (err) { - locale = navigator.language || navigator.userLanguage; + locale = navigator.languages[0]; + language = locale.split('-')[0]; } else { locale = data.language; + language = locale.split('-')[0]; } - if (locale === 'ru') { - locale = 'ru-RU'; - } else if (locale === 'de') { - locale = 'de-DE'; - } else { - locale = 'en-US'; + + /* consider the region only for selected common exceptions where the date/number formats + are significantly different than the language's default. + If more are needed change the gulpfile.js too and run the 'vendor-angular-i18n' gulp task */ + if (['es-ar', 'de-at', 'en-au', 'fr-be', 'es-bo', 'pt-br', 'en-ca', + 'fr-ca', 'fr-ch', 'es-co', 'en-gb', 'en-hk', 'zh-hk', 'en-ie', + 'en-in', 'fr-lu', 'es-mx', 'en-nz', 'en-sg', 'zh-sg', + 'es-us', 'zh-tw', 'en-za'].indexOf(locale.toLowerCase()) < 0) { + locale = language; + } + + if (language !== "en") { + console.log('Setting interface language to: ' + language); + $translate.use(language); } + console.log('Setting locale to: ' + locale); deferred.resolve(locale); }); });