gui: Sort languages alphabetically (fixes #3813)

This change sorts the language selection menu in Syncthing's home page so
that the languages are displayed alphabetically. The issue was discussed in
#3813. There were few ways of doing this. Sorting the language names in
transifix file did not work due to access control. So I sorted the languages
directly in languageSelectdirective.js by inverting and sorting the language
info retrieved from localeService.js.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4052
This commit is contained in:
Jaya chithra 2017-03-22 05:15:32 +00:00 committed by Jakob Borg
parent e667fcb472
commit 53a7c7bd49

View File

@ -6,8 +6,8 @@ angular.module('syncthing.core')
template: template:
'<a ng-if="visible" href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><span class="fa fa-globe"></span><span class="hidden-xs">&nbsp;{{localesNames[currentLocale] || "English"}}</span> <span class="caret"></span></a>'+ '<a ng-if="visible" href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><span class="fa fa-globe"></span><span class="hidden-xs">&nbsp;{{localesNames[currentLocale] || "English"}}</span> <span class="caret"></span></a>'+
'<ul ng-if="visible" class="dropdown-menu">'+ '<ul ng-if="visible" class="dropdown-menu">'+
'<li ng-repeat="(i,name) in localesNames" ng-class="{active: i==currentLocale}">'+ '<li ng-repeat="name in localesNamesInvKeys" ng-class="{active: localesNamesInv[name]==currentLocale}">'+
'<a href="#" data-ng-click="changeLanguage(i)">{{name}}</a>'+ '<a href="#" data-ng-click="changeLanguage(localesNamesInv[name])">{{name}}</a>'+
'</li>'+ '</li>'+
'</ul>', '</ul>',
@ -26,8 +26,21 @@ angular.module('syncthing.core')
availableLocaleNames[a] = '[' + a + ']'; availableLocaleNames[a] = '[' + a + ']';
} }
} }
$scope.localesNames = availableLocaleNames; $scope.localesNames = availableLocaleNames;
var invert = function (obj) {
var new_obj = {};
for (var prop in obj) {
if(obj.hasOwnProperty(prop)) {
new_obj[obj[prop]] = prop;
}
}
return new_obj;
};
$scope.localesNamesInv = invert($scope.localesNames);
$scope.localesNamesInvKeys = Object.keys($scope.localesNamesInv).sort();
$scope.visible = $scope.localesNames && $scope.localesNames['en']; $scope.visible = $scope.localesNames && $scope.localesNames['en'];
// using $watch cause LocaleService.currentLocale will be change after receive async query accepted-languages // using $watch cause LocaleService.currentLocale will be change after receive async query accepted-languages