refactor ux language handling
This commit is contained in:
parent
39e6a81b62
commit
55afc4d9d4
8 changed files with 125 additions and 81 deletions
|
|
@ -75,7 +75,7 @@
|
||||||
<span translate>Language</span>
|
<span translate>Language</span>
|
||||||
<span class="right text-gray">
|
<span class="right text-gray">
|
||||||
<i class="icon-arrow-right3 size-24 right"></i>
|
<i class="icon-arrow-right3 size-24 right"></i>
|
||||||
{{index.defaultLanguageName|translate}}
|
{{preferences.currentLanguageName|translate}}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<li class="line-b p20" ng-show="!index.noFocusedWallet" ng-click="$root.go('preferencesUnit')">
|
<li class="line-b p20" ng-show="!index.noFocusedWallet" ng-click="$root.go('preferencesUnit')">
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<div class="content preferences" ng-controller="preferencesLanguageController as prefLang">
|
<div class="content preferences" ng-controller="preferencesLanguageController as prefLang">
|
||||||
<div class="animated infinite flash text-center m20t text-gray" ng-show="prefLang.loading" translate>Applying changes</div>
|
<div class="animated infinite flash text-center m20t text-gray" ng-show="prefLang.loading" translate>Applying changes</div>
|
||||||
<div ng-show="!prefLang.loading"
|
<div ng-show="!prefLang.loading"
|
||||||
ng-repeat="lang in index.availableLanguages"
|
ng-repeat="lang in prefLang.availableLanguages"
|
||||||
ng-click="prefLang.save(lang.isoCode)" class="line-b p20 size-14">
|
ng-click="prefLang.save(lang.isoCode)" class="line-b p20 size-14">
|
||||||
<span>{{lang.name}}</span>
|
<span>{{lang.name}}</span>
|
||||||
<i class="fi-check size-16 right" ng-show="index.defaultLanguageIsoCode == lang.isoCode"></i>
|
<i class="fi-check size-16 right" ng-show="index.defaultLanguageIsoCode == lang.isoCode"></i>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment, nodeWebkit, addonManager, feeService, isChromeApp, bwsError, txFormatService, glideraService, $state) {
|
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettext, amMoment, nodeWebkit, addonManager, feeService, isChromeApp, bwsError, txFormatService, uxLanguage, $state, glideraService) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.isCordova = isCordova;
|
self.isCordova = isCordova;
|
||||||
self.onGoingProcess = {};
|
self.onGoingProcess = {};
|
||||||
|
|
@ -39,35 +39,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
|
|
||||||
self.tab = 'walletHome';
|
self.tab = 'walletHome';
|
||||||
|
|
||||||
self.availableLanguages = [{
|
|
||||||
name: 'English',
|
|
||||||
isoCode: 'en',
|
|
||||||
}, {
|
|
||||||
name: 'Français',
|
|
||||||
isoCode: 'fr',
|
|
||||||
}, {
|
|
||||||
name: 'Italiano',
|
|
||||||
isoCode: 'it',
|
|
||||||
}, {
|
|
||||||
name: 'Deutsch',
|
|
||||||
isoCode: 'de',
|
|
||||||
}, {
|
|
||||||
name: 'Español',
|
|
||||||
isoCode: 'es',
|
|
||||||
}, {
|
|
||||||
name: 'Português',
|
|
||||||
isoCode: 'pt',
|
|
||||||
}, {
|
|
||||||
name: 'Ελληνικά',
|
|
||||||
isoCode: 'el',
|
|
||||||
}, {
|
|
||||||
name: '日本語',
|
|
||||||
isoCode: 'ja',
|
|
||||||
}, {
|
|
||||||
name: 'Pусский',
|
|
||||||
isoCode: 'ru',
|
|
||||||
}];
|
|
||||||
|
|
||||||
self.feeOpts = feeService.feeOpts;
|
self.feeOpts = feeService.feeOpts;
|
||||||
|
|
||||||
self.setOngoingProcess = function(processName, isOn) {
|
self.setOngoingProcess = function(processName, isOn) {
|
||||||
|
|
@ -827,29 +798,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
};
|
};
|
||||||
|
|
||||||
self.setUxLanguage = function() {
|
self.setUxLanguage = function() {
|
||||||
var userLang = configService.getSync().wallet.settings.defaultLanguage;
|
var userLang = uxLanguage.update();
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.defaultLanguageIsoCode = userLang;
|
self.defaultLanguageIsoCode = userLang;
|
||||||
self.defaultLanguageName = lodash.result(lodash.find(self.availableLanguages, {
|
self.defaultLanguageName = uxLanguage.getName(userLang);
|
||||||
'isoCode': self.defaultLanguageIsoCode
|
|
||||||
}), 'name');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.initGlidera = function(accessToken) {
|
self.initGlidera = function(accessToken) {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesController',
|
angular.module('copayApp.controllers').controller('preferencesController',
|
||||||
function($scope, $rootScope, $filter, $timeout, $modal, $log, lodash, configService, profileService) {
|
function($scope, $rootScope, $filter, $timeout, $modal, $log, lodash, configService, profileService, uxLanguage) {
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
this.unitName = config.wallet.settings.unitName;
|
this.unitName = config.wallet.settings.unitName;
|
||||||
this.bwsurl = config.bws.url;
|
this.bwsurl = config.bws.url;
|
||||||
|
this.currentLanguageName = uxLanguage.getCurrentLanguageName();
|
||||||
this.selectedAlternative = {
|
this.selectedAlternative = {
|
||||||
name: config.wallet.settings.alternativeName,
|
name: config.wallet.settings.alternativeName,
|
||||||
isoCode: config.wallet.settings.alternativeIsoCode
|
isoCode: config.wallet.settings.alternativeIsoCode
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesLanguageController',
|
angular.module('copayApp.controllers').controller('preferencesLanguageController',
|
||||||
function($scope, $log, $timeout, configService, go) {
|
function($scope, $log, $timeout, configService, go, uxLanguage) {
|
||||||
|
|
||||||
|
this.availableLanguages = uxLanguage.getLanguages();
|
||||||
|
|
||||||
|
console.log('[preferencesLanguage.js.7]', this.availableLanguages); //TODO
|
||||||
this.save = function(newLang) {
|
this.save = function(newLang) {
|
||||||
|
|
||||||
var opts = {
|
var opts = {
|
||||||
|
|
|
||||||
|
|
@ -463,22 +463,10 @@ angular
|
||||||
needProfile: false
|
needProfile: false
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.run(function($rootScope, $state, $log, gettextCatalog, uriHandler, isCordova, amMoment, profileService, $timeout, nodeWebkit) {
|
.run(function($rootScope, $state, $log, uriHandler, isCordova, profileService, $timeout, nodeWebkit, uxLanguage) {
|
||||||
FastClick.attach(document.body);
|
FastClick.attach(document.body);
|
||||||
|
|
||||||
// Auto-detect browser language
|
uxLanguage.init();
|
||||||
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';
|
|
||||||
gettextCatalog.setCurrentLanguage(userLang);
|
|
||||||
amMoment.changeLocale(userLang);
|
|
||||||
|
|
||||||
// Register URI handler, not for mobileApp
|
// Register URI handler, not for mobileApp
|
||||||
if (!isCordova) {
|
if (!isCordova) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, storageService, bwcService, configService, notificationService, isChromeApp, isCordova, gettext, nodeWebkit, bwsError, ledger) {
|
.factory('profileService', function profileServiceFactory($rootScope, $location, $timeout, $filter, $log, lodash, storageService, bwcService, configService, notificationService, isChromeApp, isCordova, gettext, nodeWebkit, bwsError, ledger, uxLanguage) {
|
||||||
|
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
|
|
@ -165,11 +165,20 @@ angular.module('copayApp.services')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root._seedWallet = function(walletClient) {
|
root._seedWallet = function(walletClient, network) {
|
||||||
var config = configService.getSync().wallet.settings;
|
var lang = uxLanguage.getCurrentLanguage();
|
||||||
console.log('[profileService.js.169:config:]',config); //TODO
|
|
||||||
asdd;
|
try {
|
||||||
walletClient.seedFromRandomWithMnemonic('livenet',null, mnemonicLang);
|
walletClient.seedFromRandomWithMnemonic(network, null, lang);
|
||||||
|
} catch (e) {
|
||||||
|
$log.info('Error creating seed: ' + e.message);
|
||||||
|
if (e.message.indexOf('language') > 0) {
|
||||||
|
$log.info('Using default language for mnemonic');
|
||||||
|
walletClient.seedFromRandomWithMnemonic(network);
|
||||||
|
} else {
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
root._createNewProfile = function(opts, cb) {
|
root._createNewProfile = function(opts, cb) {
|
||||||
|
|
@ -179,7 +188,7 @@ asdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
var walletClient = bwcService.getClient();
|
var walletClient = bwcService.getClient();
|
||||||
this._seedWallet(walletClient);
|
root._seedWallet(walletClient, 'livenet');
|
||||||
|
|
||||||
walletClient.createWallet('Personal Wallet', 'me', 1, 1, {
|
walletClient.createWallet('Personal Wallet', 'me', 1, 1, {
|
||||||
network: 'livenet'
|
network: 'livenet'
|
||||||
|
|
@ -209,10 +218,7 @@ asdd;
|
||||||
return cb(gettext('Could not create using the specified extended public key'));
|
return cb(gettext('Could not create using the specified extended public key'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO LANG...
|
root._seedWallet(walletClient, opts.networkName);
|
||||||
// TODO...
|
|
||||||
$log.warn("TODO LANG!")
|
|
||||||
walletClient.seedFromRandomWithMnemonic(opts.networkName);
|
|
||||||
|
|
||||||
walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, {
|
walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, {
|
||||||
network: opts.networkName
|
network: opts.networkName
|
||||||
|
|
|
||||||
95
src/js/services/uxLanguage.js
Normal file
95
src/js/services/uxLanguage.js
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
'use strict';
|
||||||
|
angular.module('copayApp.services')
|
||||||
|
.factory('uxLanguage', function languageService($log, lodash, gettextCatalog, amMoment, configService) {
|
||||||
|
var root = {};
|
||||||
|
|
||||||
|
root.availableLanguages = [{
|
||||||
|
name: 'English',
|
||||||
|
isoCode: 'en',
|
||||||
|
}, {
|
||||||
|
name: 'Français',
|
||||||
|
isoCode: 'fr',
|
||||||
|
}, {
|
||||||
|
name: 'Italiano',
|
||||||
|
isoCode: 'it',
|
||||||
|
}, {
|
||||||
|
name: 'Deutsch',
|
||||||
|
isoCode: 'de',
|
||||||
|
}, {
|
||||||
|
name: 'Español',
|
||||||
|
isoCode: 'es',
|
||||||
|
}, {
|
||||||
|
name: 'Português',
|
||||||
|
isoCode: 'pt',
|
||||||
|
}, {
|
||||||
|
name: 'Ελληνικά',
|
||||||
|
isoCode: 'el',
|
||||||
|
}, {
|
||||||
|
name: '日本語',
|
||||||
|
isoCode: 'ja',
|
||||||
|
}, {
|
||||||
|
name: 'Pусский',
|
||||||
|
isoCode: 'ru',
|
||||||
|
}];
|
||||||
|
|
||||||
|
root.currentLanguage = null;
|
||||||
|
|
||||||
|
root._detect = function() {
|
||||||
|
// 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';
|
||||||
|
|
||||||
|
return userLang;
|
||||||
|
};
|
||||||
|
|
||||||
|
root._set = function(lang) {
|
||||||
|
$log.debug('Setting default language: ' + lang);
|
||||||
|
gettextCatalog.setCurrentLanguage(lang);
|
||||||
|
amMoment.changeLocale(lang);
|
||||||
|
root.currentLanguage = lang;
|
||||||
|
};
|
||||||
|
|
||||||
|
root.getCurrentLanguage = function() {
|
||||||
|
return root.currentLanguage;
|
||||||
|
};
|
||||||
|
|
||||||
|
root.getCurrentLanguageName = function() {
|
||||||
|
return root.getName(root.currentLanguage);
|
||||||
|
};
|
||||||
|
|
||||||
|
root.getLanguages = function() {
|
||||||
|
return root.availableLanguages;
|
||||||
|
};
|
||||||
|
|
||||||
|
root.init = function() {
|
||||||
|
root._set(root._detect());
|
||||||
|
};
|
||||||
|
|
||||||
|
root.update = function() {
|
||||||
|
var userLang = configService.getSync().wallet.settings.defaultLanguage;
|
||||||
|
|
||||||
|
if (!userLang) {
|
||||||
|
userLang = root._detect();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userLang != gettextCatalog.getCurrentLanguage()) {
|
||||||
|
root._set(userLang);
|
||||||
|
}
|
||||||
|
return userLang;
|
||||||
|
};
|
||||||
|
|
||||||
|
root.getName = function(lang) {
|
||||||
|
return lodash.result(lodash.find(root.availableLanguages, {
|
||||||
|
'isoCode': lang
|
||||||
|
}), 'name');
|
||||||
|
};
|
||||||
|
|
||||||
|
return root;
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue