Commit 2862bb23 authored by Benoit Lavenier's avatar Benoit Lavenier

[fix] Fix locale change

[enh] Add country flag for each locales
parent b535ab7f
Pipeline #6150 passed with stages
in 4 minutes and 54 seconds
......@@ -57,9 +57,11 @@ angular.module('cesium-api', ['ionic', 'ionic-material', 'ngMessages', 'pascalpr
$urlRouterProvider.otherwise('/app/home');
})
.controller('ApiCtrl', function ($scope, $state, $translate, $ionicPopover, Modals, csSettings){
.controller('ApiCtrl', function ($scope, $state, $translate, $ionicPopover, UIUtils, Modals, csSettings){
'ngInject';
// Fill locales
$scope.locales = angular.copy(csSettings.locales);
$scope.showAboutModal = function(e) {
e.preventDefault(); // avoid to open link href
......
......@@ -6,13 +6,13 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
// Define app locales
var locales = [
{id:'en', label:'English'},
{id:'en-GB', label:'English (UK)'},
{id:'en', label:'English', country: 'us'},
{id:'en-GB', label:'English (UK)', country: 'gb'},
{id:'eo-EO', label:'Esperanto'},
{id:'fr-FR', label:'Français'},
{id:'nl-NL', label:'Nederlands'},
{id:'es-ES', label:'Spanish'},
{id:'it-IT', label:'Italiano'}
{id:'fr-FR', label:'Français' , country: 'fr'},
{id:'nl-NL', label:'Nederlands', country: 'nl'},
{id:'es-ES', label:'Spanish', country: 'es'},
{id:'it-IT', label:'Italiano', country: 'it'}
];
var fallbackLocale = csConfig.fallbackLanguage ? fixLocale(csConfig.fallbackLanguage) : 'en';
......@@ -201,7 +201,8 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
var localeChanged = false;
if (newData.locale && newData.locale.id) {
// Fix previously stored locale (could use bad format)
newData.locale.id = fixLocale(newData.locale.id);
var localeId = fixLocale(newData.locale.id);
newData.locale = _.findWhere(locales, {id: localeId});
localeChanged = !data.locale || newData.locale.id !== data.locale.id || newData.locale.id !== $translate.use();
}
......@@ -218,7 +219,9 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
// Apply the new locale (only if need)
// will produce an event cached by onLocaleChange();
if (localeChanged) $translate.use(data.locale.id);
if (localeChanged) {
$translate.use(data.locale.id);
}
},
......
......@@ -4,12 +4,16 @@
</ion-nav-title>
<ion-nav-buttons side="right">
<!-- locales -->
<button class="button button-clear hidden-xs hidden-sm gray icon-left"
<!-- locales -->
<img ng-if="$root.settings.locale.country"
ng-src="https://www.countryflags.io/{{$root.settings.locale.country}}/shiny/32.png"
style="padding: 5px 0"
ng-click="showLocalesPopover($event)">
<button class="button button-clear hidden-xs hidden-sm gray"
style="max-width: 450px !important"
ng-click="showLocalesPopover($event)">
<i class="icon ion-earth" ></i>
{{$root.settings.locale.label}}
{{$root.settings.locale.label}}&nbsp;
<small class="ion-arrow-down-b"></small>
</button>
</ion-nav-buttons>
......
......@@ -5,6 +5,8 @@
<a ng-repeat="l in locales track by l.id"
class="item item-icon-left ink"
ng-click="changeLanguage(l.id)">
<i class="item-image avatar"
style="background-image: url(https://www.countryflags.io/{{l.country}}/flat/32.png)"></i>
{{l.label | translate}}
</a>
......
......@@ -10,12 +10,17 @@
</ion-nav-title>
<ion-nav-buttons side="right">
<!-- locales -->
<button class="button button-clear hidden-xs hidden-sm gray icon-left"
<!-- locales -->
<img ng-if="$root.settings.locale.country"
ng-src="https://www.countryflags.io/{{$root.settings.locale.country}}/shiny/32.png"
style="padding: 5px 0"
ng-click="showLocalesPopover($event)">
<button class="button button-clear hidden-xs hidden-sm gray"
style="max-width: 450px !important"
ng-click="showLocalesPopover($event)">
<i class="icon ion-earth" ></i>
{{$root.settings.locale.label}}
{{$root.settings.locale.label}}&nbsp;
<small class="ion-arrow-down-b"></small>
</button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment