From a098d97b5a8dc62ccc2eb2e04a8e722440cd7122 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 1 Jun 2026 14:28:17 +0200 Subject: [PATCH] Bug 42727: List languages in a determinist order The list of languages are displayed in a random order in: * language picker at the bottom of the page * language tab when editing a notice template or an additional content This patch fixes it to display them in a determinist order Test plan: Have several languages installed, and some of them enabled, change the order of the languages in the syspref Reload the mainpage several times and notice that the languages are always displayed in the same order. Same when editing a notice template or an additional content. Note that I have not investigated yet why on the notice template and additinal content edit views they are not listed in the same order. Signed-off-by: David Nind Signed-off-by: Nick Clemens Signed-off-by: Pedro Amorim --- C4/Languages.pm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/C4/Languages.pm b/C4/Languages.pm index 36da463c2b..ec1eabaa8f 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -369,14 +369,16 @@ FIXME: this could be rewritten and simplified using map sub _build_languages_arrayref { my ( $translated_languages, $current_language, $enabled_languages ) = @_; + $current_language //= ''; my @translated_languages = @$translated_languages; my @languages_loop; # the final reference to an array of hashrefs my @enabled_languages = @$enabled_languages; # how many languages are enabled, if one, take note, some contexts won't need to display it - my $language_groups; - my $track_language_groups; + my $language_groups = {}; + my $track_language_groups = {}; + my $current_language_regex = regex_lang_subtags($current_language); # Loop through the translated languages @@ -443,9 +445,15 @@ sub _build_languages_arrayref { } } } - ( exists $idx{$aa} and exists $idx{$bb} and ( $idx{$aa} cmp $idx{$bb} ) ) - || ( exists $idx{$aa} and exists $idx{$bb} ) - || exists $idx{$bb} + if ( exists $idx{$aa} and exists $idx{$bb} ) { + return $idx{$aa} cmp $idx{$bb}; + } elsif ( exists $idx{$aa} ) { + return -1; + } elsif ( exists $idx{$bb} ) { + return 1; + } else { + return $a cmp $b; # Finally order by lang code + } } keys %$language_groups; for my $key (@ordered_keys) {