select interface language by detecting browser language when opening AriaNg first

This commit is contained in:
MaysWind 2016-07-13 23:35:23 +08:00
parent b091a1499b
commit 5f5fd7087b

View file

@ -1,7 +1,23 @@
(function () { (function () {
'use strict'; 'use strict';
angular.module('ariaNg').factory('ariaNgSettingService', ['$location', '$filter', '$translate', 'base64', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', function ($location, $filter, $translate, base64, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages) { angular.module('ariaNg').factory('ariaNgSettingService', ['$window', '$location', '$filter', '$translate', 'base64', 'amMoment', 'localStorageService', 'ariaNgConstants', 'ariaNgDefaultOptions', 'ariaNgLanguages', function ($window, $location, $filter, $translate, base64, amMoment, localStorageService, ariaNgConstants, ariaNgDefaultOptions, ariaNgLanguages) {
var getDefaultLanguage = function () {
var browserLang = $window.navigator.browserLanguage ? $window.navigator.browserLanguage : $window.navigator.language;
if (!browserLang) {
return ariaNgDefaultOptions.language;
}
browserLang = browserLang.replace(/\-/g, "_");
if (!ariaNgLanguages[browserLang]) {
return ariaNgDefaultOptions.language;
}
return browserLang;
};
var getDefaultRpcHost = function () { var getDefaultRpcHost = function () {
return $location.$$host; return $location.$$host;
}; };
@ -15,6 +31,8 @@
if (!options) { if (!options) {
options = angular.extend({}, ariaNgDefaultOptions); options = angular.extend({}, ariaNgDefaultOptions);
options.language = getDefaultLanguage();
setOptions(options); setOptions(options);
} }