Skip to content
Snippets Groups Projects
Commit c06f6866 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

- move locale list from UIUtils to settings-services

- use locales list to fixLocale() (in settings-services)
parent 0f0299fd
No related branches found
No related tags found
No related merge requests found
......@@ -267,10 +267,12 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht
$animateProvider.classNameFilter( /\banimate-/ );
})
// Configure cache (used by HTTP requests) default max age
.config(function (CacheFactoryProvider) {
angular.extend(CacheFactoryProvider.defaults, { maxAge: 60 * 1000 /*1min*/});
})
// Configure screen size detection
.config(function(screenmatchConfigProvider) {
screenmatchConfigProvider.config.rules = 'bootstrap';
})
......@@ -280,6 +282,8 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht
// JS scrolling need for iOs (see http://blog.ionic.io/native-scrolling-in-ionic-a-tale-in-rhyme/)
var enableJsScrolling = ionic.Platform.isIOS();
$ionicConfigProvider.scrolling.jsScrolling(enableJsScrolling);
// Configure the view cache
$ionicConfigProvider.views.maxCache(5);
})
......@@ -292,7 +296,7 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht
$rootScope.device = Device;
// removeIf(device)
// Automatic redirection to large state (if exists)
// Automatic redirection to large state (if define)
$rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) {
if (next.data.large && !UIUtils.screen.isSmall()) {
var redirect = !$rootScope.tour && !event.currentScope.tour; // disabled for help tour
......@@ -304,7 +308,7 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht
});
// endRemoveIf(device)
// We use 'Device.ready()' instead of '$ionicPlatform.ready()', because it could be call many times
// We use 'Device.ready()' instead of '$ionicPlatform.ready()', because this one is callable many times
Device.ready()
.then(function() {
......@@ -329,9 +333,8 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht
// UIUtils.disableEffects();
}
})
// Status bar
// Status bar style
.then(function() {
ionic.Platform.fullScreen();
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
......@@ -348,7 +351,7 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht
}
catch(err) {
moment.locale('en');
console.warn('[app] Unknown local for moment lib. Using default');
console.warn('[app] Unknown local for moment lib. Using default [en]');
}
// config numeral lib
......@@ -357,7 +360,7 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht
}
catch(err) {
numeral.language('en');
console.warn('[app] Unknown local for numeral lib. Using default');
console.warn('[app] Unknown local for numeral lib. Using default [en]');
}
// Set some translation need by filters
......
......@@ -39,7 +39,7 @@ function SettingsController($scope, $q, $ionicPopup, $timeout, $translate, csHtt
$scope.loading = true; // to avoid the call of csWallet.store()
// Fill locales
$scope.locales = angular.copy(UIUtils.locales);
$scope.locales = angular.copy(csSettings.locales);
var locale = _.findWhere($scope.locales, {id: csSettings.defaultSettings.locale.id});
angular.merge($scope.formData, csSettings.data);
$scope.formData.locale = locale;
......
angular.module('cesium.settings.services', ['ngResource', 'ngApi', 'cesium.config', 'cesium.device.services'])
.factory('csSettings', function($q, Api, localStorage, $translate, csConfig, Device, $rootScope) {
.factory('csSettings', function($q, Api, localStorage, $translate, csConfig, Device) {
'ngInject';
CSSettings = function(id) {
// Define app locales
var locales = [
{id:'en', label:'English'},
{id:'en-GB', label:'English (UK)'},
{id:'fr-FR', label:'Français'},
{id:'nl-NL', label:'Nederlands'}
];
var fallbackLocale = csConfig.fallbackLanguage ? fixLocale(csConfig.fallbackLanguage) : 'en';
// Convert browser locale to app locale (fix #140)
function fixLocale (locale) {
// convert in app locale (fix #140)
return locale && locale.startsWith('fr') ? 'fr-FR' : 'en';
if (!locale) return fallbackLocale;
// exists in app locales: use it
if (_.findWhere(locales, {id: locale})) return locale;
// not exists: reiterate with the root(e.g. 'fr-XX' -> 'fr')
var localeParts = locale.split('-');
if (localeParts.length > 1) {
return fixLocale(localeParts[0]);
}
// If another locale exists with the same root: use it
var similarLocale = _.find(locales, function(l) {
return l.startsWith(locale);
});
if (similarLocale) return similarLocale;
return fallbackLocale;
}
var
......@@ -172,7 +198,8 @@ angular.module('cesium.settings.services', ['ngResource', 'ngApi', 'cesium.confi
restore: restore,
defaultSettings: defaultSettings,
// api extension
api: api
api: api,
locales: locales
};
};
......
......@@ -623,13 +623,7 @@ angular.module('cesium.utils.services', ['ngResource'])
image: {
resizeFile: resizeImageFromFile,
resizeSrc: resizeImageFromSrc
},
locales: [
{id:'en', label:'English'},
{id:'en-GB', label:'English (UK)'},
{id:'fr-FR', label:'Français'},
{id:'nl-NL', label:'Nederlands'}
]
}
};
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment