From 5f5fd7087b9b8975a396c38878d792c70c0a4d0b Mon Sep 17 00:00:00 2001 From: MaysWind Date: Wed, 13 Jul 2016 23:35:23 +0800 Subject: [PATCH] select interface language by detecting browser language when opening AriaNg first --- src/scripts/services/ariaNgSettingService.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/scripts/services/ariaNgSettingService.js b/src/scripts/services/ariaNgSettingService.js index 3de6132..3ea7628 100644 --- a/src/scripts/services/ariaNgSettingService.js +++ b/src/scripts/services/ariaNgSettingService.js @@ -1,7 +1,23 @@ (function () { '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 () { return $location.$$host; }; @@ -15,6 +31,8 @@ if (!options) { options = angular.extend({}, ariaNgDefaultOptions); + options.language = getDefaultLanguage(); + setOptions(options); }