-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget-locale.js
38 lines (34 loc) · 1.28 KB
/
get-locale.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(window.location.toString());
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var getLocale = (function() {
var locale = decodeURIComponent(getParameterByName('sLocale'));
if(!locale) {
locale = window.config ? window.config.defaultLocale : 'en';
}
var idx = locale.indexOf('_');
if(idx > -1) {
var localeLang = locale.substring(0, idx);
var localeCountry = locale.substring(idx+1);
} else {
var localeLang = locale;
var localeCountry = null;
}
var getAngularLocale = function(callback) {
$.getScript('bower_components/angular-i18n/angular-locale_' + locale.replace('_', '-') + '.js')
.success(callback)
.fail(function() {
$.getScript('bower_components/angular-i18n/angular-locale_' + window.config.defaultLocale.replace('_', '-') + '.js')
.always(callback);
});
}
return {
locale: locale,
localeLang: localeLang,
localeCountry: localeCountry,
getAngularLocale: getAngularLocale
};
})();