fix default language
This commit is contained in:
parent
72b7ca7fb9
commit
f237c783a9
2 changed files with 29 additions and 13 deletions
|
|
@ -94,6 +94,9 @@ if [ ! -d $PROJECT ]; then
|
||||||
checkOK
|
checkOK
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cordova plugin add cordova-plugin-globalization
|
||||||
|
checkOK
|
||||||
|
|
||||||
cordova plugin add cordova-plugin-splashscreen
|
cordova plugin add cordova-plugin-splashscreen
|
||||||
checkOK
|
checkOK
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('uxLanguage', function languageService($log, lodash, gettextCatalog, amMoment, configService) {
|
.factory('uxLanguage', function languageService($log, $timeout, lodash, gettextCatalog, amMoment, configService) {
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
root.availableLanguages = [{
|
root.availableLanguages = [{
|
||||||
|
|
@ -26,16 +26,24 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
root.currentLanguage = null;
|
root.currentLanguage = null;
|
||||||
|
|
||||||
root._detect = function() {
|
root._detect = function(cb) {
|
||||||
// Auto-detect browser language
|
|
||||||
var userLang, androidLang;
|
|
||||||
|
|
||||||
if (navigator && navigator.userAgent && (androidLang = navigator.userAgent.match(/android.*\W(\w\w)-(\w\w)\W/i))) {
|
var userLang, androidLang;
|
||||||
userLang = androidLang[1];
|
if (navigator && navigator.globalization) {
|
||||||
|
|
||||||
|
navigator.globalization.getPreferredLanguage(function(preferedLanguage) {
|
||||||
|
// works for iOS and Android 4.x
|
||||||
|
userLang = preferedLanguage.value;
|
||||||
|
userLang = userLang ? (userLang.split('-', 1)[0] || 'en') : 'en';
|
||||||
|
return cb(userLang);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// works for iOS and Android 4.x
|
// Auto-detect browser language
|
||||||
userLang = navigator.userLanguage || navigator.language;
|
userLang = navigator.userLanguage || navigator.language;
|
||||||
|
userLang = userLang ? (userLang.split('-', 1)[0] || 'en') : 'en';
|
||||||
|
return cb(userLang);
|
||||||
}
|
}
|
||||||
|
|
||||||
userLang = userLang ? (userLang.split('-', 1)[0] || 'en') : 'en';
|
userLang = userLang ? (userLang.split('-', 1)[0] || 'en') : 'en';
|
||||||
|
|
||||||
// Set only available languages
|
// Set only available languages
|
||||||
|
|
@ -72,20 +80,25 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.init = function() {
|
root.init = function() {
|
||||||
root._set(root._detect());
|
root._detect(function(lang) {
|
||||||
|
root._set(lang);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.update = function() {
|
root.update = function() {
|
||||||
var userLang = configService.getSync().wallet.settings.defaultLanguage;
|
var userLang = configService.getSync().wallet.settings.defaultLanguage;
|
||||||
|
|
||||||
if (!userLang) {
|
if (!userLang) {
|
||||||
userLang = root._detect();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userLang != gettextCatalog.getCurrentLanguage()) {
|
root._detect(function(lang) {
|
||||||
root._set(userLang);
|
userLang = lang;
|
||||||
|
|
||||||
|
if (userLang != root.currentLanguage) {
|
||||||
|
root._set(lang);
|
||||||
|
}
|
||||||
|
return userLang;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return userLang;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getName = function(lang) {
|
root.getName = function(lang) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue