From 817a10be14311ebd7f01065bf49197d4fc10675d Mon Sep 17 00:00:00 2001 From: Davide Colombo Date: Fri, 8 Apr 2016 11:37:20 +0200 Subject: [PATCH] FS-9006 - [verto_communicator] add-combobox for languages --- .../src/locales/locale-en.json | 4 +- .../src/locales/locale-it.json | 4 +- .../src/partials/settings.html | 8 ++ .../src/storageService/services/storage.js | 3 +- .../src/vertoApp/vertoApp.module.js | 91 ++++++++++++------- .../controllers/MainController.js | 6 ++ .../controllers/SettingsController.js | 27 +++++- 7 files changed, 104 insertions(+), 39 deletions(-) diff --git a/html5/verto/verto_communicator/src/locales/locale-en.json b/html5/verto/verto_communicator/src/locales/locale-en.json index 5aa607d860..c8c59ace10 100644 --- a/html5/verto/verto_communicator/src/locales/locale-en.json +++ b/html5/verto/verto_communicator/src/locales/locale-en.json @@ -147,5 +147,7 @@ "CHAT_VOL_MINUS": "Vol -", "CHAT_VOL_PLUS": "Vol +", "CHAT_GAIN_MINUS": "Gain -", - "CHAT_GAIN_PLUS": "Gain +" + "CHAT_GAIN_PLUS": "Gain +", + "LANGUAGE": "Language:", + "BROWSER_LANGUAGE": "Browser Language" } diff --git a/html5/verto/verto_communicator/src/locales/locale-it.json b/html5/verto/verto_communicator/src/locales/locale-it.json index 428608afab..6f33747cfd 100644 --- a/html5/verto/verto_communicator/src/locales/locale-it.json +++ b/html5/verto/verto_communicator/src/locales/locale-it.json @@ -148,6 +148,8 @@ "CHAT_VOL_MINUS": "Vol -", "CHAT_VOL_PLUS": "Vol +", "CHAT_GAIN_MINUS": "Guadagno -", - "CHAT_GAIN_PLUS": "Guadagno +" + "CHAT_GAIN_PLUS": "Guadagno +", + "LANGUAGE": "Lingua:", + "BROWSER_LANGUAGE": "Lingua del browser" } diff --git a/html5/verto/verto_communicator/src/partials/settings.html b/html5/verto/verto_communicator/src/partials/settings.html index 9848fa4e58..96d19db0b7 100644 --- a/html5/verto/verto_communicator/src/partials/settings.html +++ b/html5/verto/verto_communicator/src/partials/settings.html @@ -79,6 +79,14 @@ +
+ + +
+
diff --git a/html5/verto/verto_communicator/src/storageService/services/storage.js b/html5/verto/verto_communicator/src/storageService/services/storage.js index fada0a82f2..501b7b7ab6 100644 --- a/html5/verto/verto_communicator/src/storageService/services/storage.js +++ b/html5/verto/verto_communicator/src/storageService/services/storage.js @@ -39,7 +39,8 @@ googEchoCancellation: true, autoBand: true, testSpeedJoin: true, - bestFrameRate: "15" + bestFrameRate: "15", + language: undefined }; data.$default(defaultSettings); diff --git a/html5/verto/verto_communicator/src/vertoApp/vertoApp.module.js b/html5/verto/verto_communicator/src/vertoApp/vertoApp.module.js index 14b39d7e55..80b81236da 100644 --- a/html5/verto/verto_communicator/src/vertoApp/vertoApp.module.js +++ b/html5/verto/verto_communicator/src/vertoApp/vertoApp.module.js @@ -20,8 +20,58 @@ 'pascalprecht.translate', ]); - vertoApp.config(['$routeProvider', 'gravatarServiceProvider', '$translateProvider', - function($routeProvider, gravatarServiceProvider, $translateProvider) { + vertoApp.constant('configLanguages', { + 'languages' : [ + {id: 'en', name: 'English'}, + {id: 'it', name: 'Italiano'}, + {id: 'fr', name: 'Français'}, + {id: 'de', name: 'Deutsch'}, + {id: 'pt', name: 'Português'}, + {id: 'pl', name: 'Polski'}, + {id: 'zh', name: '中國'}, + {id: 'ru', name: 'Pусский'}, + {id: 'sv', name: 'Svenska'}, + {id: 'da', name: 'Dansk'}, + {id: 'es', name: 'Español'}, + {id: 'id', name: 'Indonesia'} + ], + + 'dialects' : { + 'en': 'en', + 'en_GB': 'en', + 'en_US': 'en', + 'it': 'it', + 'it_IT': 'it', + 'fr': 'fr', + 'fr_FR': 'fr', + 'fr_CA': 'fr', + 'pt': 'pt', + 'pt_BR': 'pt', + 'pt_PT': 'pt', + 'de': 'de', + 'de_DE': 'de', + 'es': 'es', + 'es_ES': 'es', + 'pl': 'pl', + 'pl_PL': 'pl', + 'ru': 'ru', + 'ru_RU': 'ru', + 'sv': 'sv', + 'sv_SV': 'sv', + 'sv_FI': 'sv', + 'da': 'da', + 'da_DK': 'da', + 'id': 'id', + 'id_ID': 'id', + 'zh': 'zh', + 'zh_CN': 'zh', + 'zh_TW': 'zh', + 'zh_HK': 'zh' + } + }); + + vertoApp.config(['$routeProvider', 'gravatarServiceProvider', '$translateProvider', 'configLanguages', + function($routeProvider, gravatarServiceProvider, $translateProvider, configLanguages) { $routeProvider. when('/', { title: 'Loading', @@ -61,44 +111,17 @@ default: 'mm' // Mystery man as default for missing avatars }; + var reg_langs = []; + angular.forEach(configLanguages.languages, function(value, key) { + reg_langs.push(value.id); + }); $translateProvider .useStaticFilesLoader({ prefix: 'locales/locale-', suffix: '.json' }) - .registerAvailableLanguageKeys(['en', 'it', 'pt', 'fr', 'da', 'de', 'es', 'pl', 'ru', 'sv', 'id', 'zh'], { - 'en': 'en', - 'en_GB': 'en', - 'en_US': 'en', - 'it': 'it', - 'it_IT': 'it', - 'fr': 'fr', - 'fr_FR': 'fr', - 'fr_CA': 'fr', - 'pt': 'pt', - 'pt_BR': 'pt', - 'pt_PT': 'pt', - 'da': 'da', - 'da_DK': 'da', - 'de': 'de', - 'de_DE': 'de', - 'es': 'es', - 'es_ES': 'es', - 'pl': 'pl', - 'pl_PL': 'pl', - 'ru': 'ru', - 'ru_RU': 'ru', - 'sv': 'sv', - 'sv_SV': 'sv', - 'sv_FI': 'sv', - 'id': 'id', - 'id_ID': 'id', - 'zh': 'zh', - 'zh_CN': 'zh', - 'zh_TW': 'zh', - 'zh_HK': 'zh' - }) + .registerAvailableLanguageKeys(reg_langs, configLanguages.dialects) .preferredLanguage('en') .determinePreferredLanguage() .fallbackLanguage('en') diff --git a/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js b/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js index b3d1c6e886..b1a3794c12 100644 --- a/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js +++ b/html5/verto/verto_communicator/src/vertoControllers/controllers/MainController.js @@ -8,6 +8,12 @@ console.debug('Executing MainController.'); + if (storage.data.language && storage.data.language !== 'browser') { + $translate.use(storage.data.language); + } else { + storage.data.language = 'browser'; + } + $rootScope.master = $location.search().master; if ($location.search().watcher === 'true') { $rootScope.watcher = true; diff --git a/html5/verto/verto_communicator/src/vertoControllers/controllers/SettingsController.js b/html5/verto/verto_communicator/src/vertoControllers/controllers/SettingsController.js index 8e00bb6d29..c52cdb8c82 100644 --- a/html5/verto/verto_communicator/src/vertoControllers/controllers/SettingsController.js +++ b/html5/verto/verto_communicator/src/vertoControllers/controllers/SettingsController.js @@ -4,8 +4,8 @@ angular .module('vertoControllers') .controller('SettingsController', ['$scope', '$http', - '$location', '$rootScope', 'storage', 'verto', '$translate', 'toastr', - function($scope, $http, $location, $rootScope, storage, verto, $translate, toastr) { + '$location', '$rootScope', 'storage', 'verto', '$translate', 'toastr', 'configLanguages', + function($scope, $http, $location, $rootScope, storage, verto, $translate, toastr, configLanguages) { console.debug('Executing ModalSettingsController.'); $.material.init(); @@ -14,6 +14,15 @@ $scope.storage = storage; $scope.verto = verto; $scope.mydata = angular.copy(storage.data); + $scope.languages = configLanguages.languages; + $scope.languages.unshift({id: 'browser', name : $translate.instant('BROWSER_LANGUAGE')}); + $scope.mydata.language = storage.data.language || 'browser'; + + $rootScope.$on('$translateChangeSuccess', function () { + $translate('BROWSER_LANGUAGE').then(function (translation) { + $scope.languages[0].name = translation; + }); + }); $rootScope.$on('toggledSettings', function(e, status) { if (status) { @@ -35,6 +44,20 @@ } }; + $scope.changedLanguage = function(langKey){ + if (langKey === 'browser'){ + storage.data.language = 'browser'; + var browserlang = $translate.preferredLanguage(); + $translate.use(browserlang).then( + function(lang) {}, function(fail_lang) { + $translate.use('en'); + }); + } else { + $translate.use(langKey); + storage.data.language = langKey; + } + }; + $scope.refreshDeviceList = function() { return verto.refreshDevices(); };