From c45246053639c216b598385a2f89cf723277a3c5 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 31 Jan 2018 13:47:37 -0300 Subject: [PATCH] Bug 20115: Set the languages order with the pref values To avoid the languages to be ordered randomly, it is better to stick on a default order. Let's suppose that the order in the pref is correct. Signed-off-by: Jesse Maseto Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- C4/Languages.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/C4/Languages.pm b/C4/Languages.pm index 5e4dabd14d..1958c91628 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -342,8 +342,18 @@ sub _build_languages_arrayref { push ( @{ $language_groups->{$language_subtags_hashref->{language}} }, $language_subtags_hashref ); } # $key is a language subtag like 'en' - while( my ($key, $value) = each %$language_groups) { + my %idx = map { $enabled_languages->[$_] => $_ } reverse 0 .. @$enabled_languages-1; + my @ordered_keys = sort { + my $aa = $language_groups->{$a}->[0]->{rfc4646_subtag}; + my $bb = $language_groups->{$b}->[0]->{rfc4646_subtag}; + ( exists $idx{$aa} and exists $idx{$bb} and ( $idx{$aa} cmp $idx{$bb} ) ) + || ( exists $idx{$aa} and exists $idx{$bb} ) + || exists $idx{$bb} + } keys %$language_groups; + + for my $key ( @ordered_keys ) { + my $value = $language_groups->{$key}; # is this language group enabled? are any of the languages within it enabled? my $enabled; for my $enabled_language (@enabled_languages) { -- 2.39.5