Merge pull request #3707 from gabrielbazan7/fix/langBugAndroid1
Fix/lang bug android
This commit is contained in:
commit
3e061211d5
3 changed files with 53 additions and 28 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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1055,9 +1055,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
};
|
};
|
||||||
|
|
||||||
self.setUxLanguage = function() {
|
self.setUxLanguage = function() {
|
||||||
var userLang = uxLanguage.update();
|
uxLanguage.update(function(lang) {
|
||||||
self.defaultLanguageIsoCode = userLang;
|
var userLang = lang;
|
||||||
self.defaultLanguageName = uxLanguage.getName(userLang);
|
self.defaultLanguageIsoCode = userLang;
|
||||||
|
self.defaultLanguageName = uxLanguage.getName(userLang);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
self.initGlidera = function(accessToken) {
|
self.initGlidera = function(accessToken) {
|
||||||
|
|
@ -1216,11 +1218,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/LanguageSettingUpdated', function() {
|
$rootScope.$on('Local/LanguageSettingUpdated', function() {
|
||||||
self.setUxLanguage();
|
self.setUxLanguage(function() {
|
||||||
self.updateRemotePreferences({
|
self.updateRemotePreferences({
|
||||||
saveAll: true
|
saveAll: true
|
||||||
}, function() {
|
}, function() {
|
||||||
$log.debug('Remote preferences saved')
|
$log.debug('Remote preferences saved')
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1391,7 +1394,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.noFocusedWallet = true;
|
self.noFocusedWallet = true;
|
||||||
self.isComplete = null;
|
self.isComplete = null;
|
||||||
self.walletName = null;
|
self.walletName = null;
|
||||||
self.setUxLanguage();
|
self.setUxLanguage(function() {});
|
||||||
profileService.isDisclaimerAccepted(function(v) {
|
profileService.isDisclaimerAccepted(function(v) {
|
||||||
if (v) {
|
if (v) {
|
||||||
go.path('import');
|
go.path('import');
|
||||||
|
|
@ -1401,7 +1404,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/NewFocusedWallet', function() {
|
$rootScope.$on('Local/NewFocusedWallet', function() {
|
||||||
self.setUxLanguage();
|
self.setUxLanguage(function() {});
|
||||||
self.setFocusedWallet();
|
self.setFocusedWallet();
|
||||||
self.debounceUpdateHistory();
|
self.debounceUpdateHistory();
|
||||||
self.isDisclaimerAccepted();
|
self.isDisclaimerAccepted();
|
||||||
|
|
|
||||||
|
|
@ -26,24 +26,33 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
root.currentLanguage = null;
|
root.currentLanguage = null;
|
||||||
|
|
||||||
root._detect = function() {
|
root._detect = function(cb) {
|
||||||
// Auto-detect browser language
|
|
||||||
var userLang, androidLang;
|
var userLang, androidLang;
|
||||||
|
if (navigator && navigator.globalization) {
|
||||||
|
|
||||||
if (navigator && navigator.userAgent && (androidLang = navigator.userAgent.match(/android.*\W(\w\w)-(\w\w)\W/i))) {
|
navigator.globalization.getPreferredLanguage(function(preferedLanguage) {
|
||||||
userLang = androidLang[1];
|
// works for iOS and Android 4.x
|
||||||
|
userLang = preferedLanguage.value;
|
||||||
|
userLang = userLang ? (userLang.split('-', 1)[0] || 'en') : 'en';
|
||||||
|
// Set only available languages
|
||||||
|
userLang = root.isAvailableLanguage(userLang);
|
||||||
|
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';
|
||||||
|
// Set only available languages
|
||||||
|
userLang = root.isAvailableLanguage(userLang);
|
||||||
|
return cb(userLang);
|
||||||
}
|
}
|
||||||
userLang = userLang ? (userLang.split('-', 1)[0] || 'en') : 'en';
|
};
|
||||||
|
|
||||||
// Set only available languages
|
root.isAvailableLanguage = function(userLang) {
|
||||||
userLang = lodash.find(root.availableLanguages, {
|
return lodash.find(root.availableLanguages, {
|
||||||
'isoCode': userLang
|
'isoCode': userLang
|
||||||
}) ? userLang : 'en';
|
}) ? userLang : 'en';
|
||||||
|
|
||||||
return userLang;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root._set = function(lang) {
|
root._set = function(lang) {
|
||||||
|
|
@ -72,20 +81,30 @@ 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(cb) {
|
||||||
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 cb(userLang);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (userLang != root.currentLanguage) {
|
||||||
|
root._set(userLang);
|
||||||
|
}
|
||||||
|
return cb(userLang);
|
||||||
}
|
}
|
||||||
return userLang;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getName = function(lang) {
|
root.getName = function(lang) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue