From c0b119feeb2e76ee56c78ed71854ffa21a31a66a Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Thu, 8 Feb 2018 10:09:43 +0200 Subject: [PATCH] Bug 20160: Sort translated languages by code The language tabs in Change notices -page are in random order, and will rearrange at every page reload. This is quite irritating. Make getTranslatedLanguages return the languages always in the same order, sorted by the language code. This is better than returning them in a random one. Test plan: 1) Enable TranslateNotices 2) Install multiple languages 3) Go to Home -> Tools -> Notices & slips 4) Edit any notice 5) Reload the page multiple times. The language tabs will rearrange at random 6) Apply patch 7) Repeat 1-5. The language tabs should now always be in the same order, sorted by the language code. Do the same test to Home -> Tools -> News -> Add News item (Check the "Display location" dropdown) Check Home -> Patrons -> Add patron (the "Preferred language for notices" dropdown) Check Home -> Administration -> System preferences -> i18n/l10n (Note the order of languages listed for "language" and "opaclanguages") Check Home -> Administration -> System preferences -> Local use (Create a new preference with variable type Languages, check the language pref listed in the table) Check Home -> Administration -> Item types -> Add item type (After the Description-field, there's "Translate into other languages", click on that. In the pop-up that opens, check the language drop-down) Signed-off-by: Pasi Kallinen --- C4/Languages.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/C4/Languages.pm b/C4/Languages.pm index 5e4dabd14d..5c46265bb9 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -313,6 +313,7 @@ sub _build_languages_arrayref { $current_language //= ''; my @translated_languages = @$translated_languages; my @languages_loop; # the final reference to an array of hashrefs + my @languages_loop_sorted; my @enabled_languages = @$enabled_languages; # how many languages are enabled, if one, take note, some contexts won't need to display it my %seen_languages; # the language tags we've seen @@ -361,7 +362,8 @@ sub _build_languages_arrayref { group_enabled => $enabled, }; } - return \@languages_loop; + @languages_loop_sorted = sort{ $a->{language} cmp $b->{language} } @languages_loop; + return \@languages_loop_sorted; } sub language_get_description { -- 2.11.0