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 <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Jonathan Druart 2026-06-01 14:28:17 +02:00 committed by Pedro Amorim
parent 0f7145e4af
commit a098d97b5a
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 13 additions and 5 deletions

View File

@ -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) {