Fix translate option
This commit is contained in:
parent
764caffd74
commit
140440b224
8 changed files with 62 additions and 47 deletions
|
|
@ -5,7 +5,7 @@
|
|||
</a>
|
||||
<a ng-show="goBackToState"
|
||||
ng-click="$root.go(goBackToState); goBackToState = null"><i class="icon-arrow-left3 icon-back"></i>
|
||||
<span class="text-back" translate>Back</span>
|
||||
<span class="text-back">{{'Back'|translate}}</span>
|
||||
</a>
|
||||
</section>
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
<span translate>Language</span>
|
||||
<span class="right text-gray">
|
||||
<i class="icon-arrow-right3 size-24 right"></i>
|
||||
{{preferences.getDefaultLanguageName(index.availableLanguages)}}
|
||||
{{index.defaultLanguageName}}
|
||||
</span>
|
||||
</li>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
ng-repeat="lang in index.availableLanguages"
|
||||
ng-click="prefLang.save(lang.isoCode)" class="line-b p20 size-14">
|
||||
<span>{{lang.name}}</span>
|
||||
<i class="fi-check size-16 right" ng-show="prefLang.defaultLanguage == lang.isoCode"></i>
|
||||
<i class="fi-check size-16 right" ng-show="index.defaultLanguageIsoCode == lang.isoCode"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="extra-margin-bottom"></div>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService) {
|
||||
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, gettextCatalog, amMoment) {
|
||||
var self = this;
|
||||
self.isCordova = isCordova;
|
||||
self.onGoingProcess = {};
|
||||
self.limitHistory = 5;
|
||||
self.limitHistory = 5;
|
||||
|
||||
function strip(number) {
|
||||
return (parseFloat(number.toPrecision(12)));
|
||||
|
|
@ -433,6 +433,44 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
});
|
||||
};
|
||||
|
||||
self.setDefaultLanguage = function(setLang) {
|
||||
var userLang
|
||||
if (!setLang) {
|
||||
userLang = configService.getSync().wallet.settings.defaultLanguage;
|
||||
if (!userLang) {
|
||||
// Auto-detect browser language
|
||||
var androidLang;
|
||||
|
||||
if (navigator && navigator.userAgent && (androidLang = navigator.userAgent.match(/android.*\W(\w\w)-(\w\w)\W/i))) {
|
||||
userLang = androidLang[1];
|
||||
} else {
|
||||
// works for iOS and Android 4.x
|
||||
userLang = navigator.userLanguage || navigator.language;
|
||||
}
|
||||
userLang = userLang ? (userLang.split('-', 1)[0] || 'en') : 'en';
|
||||
}
|
||||
if (userLang != gettextCatalog.getCurrentLanguage()) {
|
||||
$log.debug('Setting default language: ' + userLang);
|
||||
gettextCatalog.setCurrentLanguage(userLang);
|
||||
amMoment.changeLocale(userLang);
|
||||
}
|
||||
}
|
||||
else {
|
||||
configService.set({
|
||||
wallet: {
|
||||
settings: {
|
||||
defaultLanguage: setLang
|
||||
}
|
||||
}
|
||||
}, function() {
|
||||
gettextCatalog.setCurrentLanguage(setLang);
|
||||
amMoment.changeLocale(setLang);
|
||||
});
|
||||
}
|
||||
self.defaultLanguageIsoCode = setLang || userLang;
|
||||
self.defaultLanguageName = lodash.result(lodash.find(self.availableLanguages, { 'isoCode': self.defaultLanguageIsoCode }), 'name');
|
||||
};
|
||||
|
||||
// UX event handlers
|
||||
$rootScope.$on('Local/ColorUpdated', function(event) {
|
||||
self.updateColor();
|
||||
|
|
@ -499,6 +537,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
});
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/DefaultLanguage', function(event, setLang) {
|
||||
self.setDefaultLanguage(setLang);
|
||||
});
|
||||
|
||||
$rootScope.$on('Animation/Disable', function(event) {
|
||||
$timeout(function() {
|
||||
self.swipeLeft = false;
|
||||
|
|
|
|||
|
|
@ -48,11 +48,6 @@ angular.module('copayApp.controllers').controller('preferencesController',
|
|||
}
|
||||
});
|
||||
|
||||
this.getDefaultLanguageName = function(availableLanguages) {
|
||||
var defaultLanguage = config.wallet.settings.defaultLanguage || 'en';
|
||||
return lodash.result(lodash.find(availableLanguages, { 'isoCode': defaultLanguage }), 'name');
|
||||
};
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
unwatch();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,24 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('preferencesLanguageController',
|
||||
function($scope, $timeout, configService, applicationService) {
|
||||
this.defaultLanguage = configService.getSync().wallet.settings.defaultLanguage || 'en';
|
||||
function($scope, $timeout, go) {
|
||||
|
||||
this.save = function(newLang) {
|
||||
var opts = {
|
||||
wallet: {
|
||||
settings: {
|
||||
defaultLanguage: newLang
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.loading = true;
|
||||
$scope.$emit('Local/DefaultLanguage', newLang);
|
||||
$timeout(function() {
|
||||
configService.set(opts, function(err) {
|
||||
if (err) console.log(err);
|
||||
applicationService.restart();
|
||||
});
|
||||
go.preferences();
|
||||
}, 100);
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -432,32 +432,21 @@ angular
|
|||
needProfile: false
|
||||
});
|
||||
})
|
||||
.run(function($rootScope, $state, $log, gettextCatalog, uriHandler, isCordova, amMoment, profileService, configService) {
|
||||
.run(function($rootScope, $state, $log, gettextCatalog, uriHandler, isCordova, amMoment, profileService) {
|
||||
|
||||
var userLang = configService.getSync().wallet.settings.defaultLanguage;
|
||||
if (!userLang) {
|
||||
// Auto-detect browser language
|
||||
var androidLang;
|
||||
// Auto-detect browser language
|
||||
var userLang, androidLang;
|
||||
|
||||
if (navigator && navigator.userAgent && (androidLang = navigator.userAgent.match(/android.*\W(\w\w)-(\w\w)\W/i))) {
|
||||
userLang = androidLang[1];
|
||||
} else {
|
||||
// works for iOS and Android 4.x
|
||||
userLang = navigator.userLanguage || navigator.language;
|
||||
}
|
||||
userLang = userLang ? (userLang.split('-', 1)[0] || 'en') : 'en';
|
||||
if (navigator && navigator.userAgent && (androidLang = navigator.userAgent.match(/android.*\W(\w\w)-(\w\w)\W/i))) {
|
||||
userLang = androidLang[1];
|
||||
} else {
|
||||
// works for iOS and Android 4.x
|
||||
userLang = navigator.userLanguage || navigator.language;
|
||||
}
|
||||
|
||||
configService.set({
|
||||
wallet: {
|
||||
settings: {
|
||||
defaultLanguage: userLang
|
||||
}
|
||||
}
|
||||
}, function() {
|
||||
gettextCatalog.setCurrentLanguage(userLang);
|
||||
amMoment.changeLocale(userLang);
|
||||
});
|
||||
userLang = userLang ? (userLang.split('-', 1)[0] || 'en') : 'en';
|
||||
gettextCatalog.setCurrentLanguage(userLang);
|
||||
amMoment.changeLocale(userLang);
|
||||
|
||||
// Register URI handler, not for mobileApp
|
||||
if (!isCordova) {
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ angular.module('copayApp.services')
|
|||
|
||||
configService.get(function(err) {
|
||||
if (err) return cb(err);
|
||||
$rootScope.$emit('Local/DefaultLanguage');
|
||||
root.setWalletClients();
|
||||
storageService.getFocusedWalletId(function(err, focusedWalletId) {
|
||||
if (err) return cb(err);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue