Commit 09dbdc45 authored by sikeda's avatar sikeda
Browse files

[-bug] (con'd r10529, 10531) ImplicatedLang(): "super" language may override...

[-bug] (con'd r10529, 10531) ImplicatedLang(): "super" language may override "sub" langauges when multiple arguments are given.  Make them to appear after.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@10534 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 662825bd
......@@ -203,19 +203,15 @@ sub CanonicLang {
sub ImplicatedLangs {
my @langs = @_;
@langs = (GetLang()) unless @langs;
@langs = ($current_lang || 'en') unless @langs;
my @implicated_langs = ();
my %implicated_langs = ();
foreach my $lang (@langs) {
my @subtags = CanonicLang($lang);
while (@subtags) {
my $l = join '-', grep {$_} @subtags;
unless ($implicated_langs{$l}) {
push @implicated_langs, $l;
$implicated_langs{$l} = 1;
}
@implicated_langs = ((grep { $_ ne $l } @implicated_langs), $l);
## Workaround:
## - "zh-Hans-CN", "zh-Hant-TW", ... may occasionally be
......@@ -223,10 +219,8 @@ sub ImplicatedLangs {
## implication list.
if ($l =~ /^zh-(Hans|Hant)-[A-Z]{2}\b/) {
$l = join '-', grep {$_} @subtags[0, 2 .. $#subtags];
unless ($implicated_langs{$l}) {
push @implicated_langs, $l;
$implicated_langs{$l} = 1;
}
@implicated_langs =
((grep { $_ ne $l } @implicated_langs), $l);
}
1 until pop @subtags;
......
......@@ -111,21 +111,27 @@ my %tests = (
## Implicated langs
ImplicatedLangs => [
['ca' => ['ca']],
['en-US' => [qw(en-US en)]],
['ca-ES-valencia' => [qw(ca-ES-valencia ca-ES ca)]],
['be-Latn' => [qw(be-Latn be)]],
['tyv-Latn-MN' => [qw(tyv-Latn-MN tyv-Latn tyv)]],
[[] => ['cs']],
[['ca'] => ['ca']],
[['en-US'] => [qw(en-US en)]],
[['ca-ES-valencia'] => [qw(ca-ES-valencia ca-ES ca)]],
[['be-Latn'] => [qw(be-Latn be)]],
[['tyv-Latn-MN'] => [qw(tyv-Latn-MN tyv-Latn tyv)]],
## zh-Hans-*/zh-Hant-* workaround
['zh-Hans-CN' => [qw(zh-Hans-CN zh-CN zh-Hans zh)]],
[ 'zh-Hant-HK-xxxxx' => [
[['zh-Hans-CN'] => [qw(zh-Hans-CN zh-CN zh-Hans zh)]],
[ ['zh-Hant-HK-xxxxx'] => [
qw(zh-Hant-HK-xxxxx zh-HK-xxxxx zh-Hant-HK zh-HK zh-Hant zh)]
],
## non-POSIX locales
['cn' => [qw(zh-CN zh)]],
[['cn'] => [qw(zh-CN zh)]],
## Old style locales
['en_US' => [qw(en-US en)]],
['nb_NO' => ['nb']],
[['en_US'] => [qw(en-US en)]],
[['nb_NO'] => ['nb']],
## Multiple arguments
[ [qw(tyv-MN tyv-Latn-MN kim tyv-Mong)] =>
[qw(tyv-MN tyv-Latn-MN tyv-Latn kim tyv-Mong tyv)]
],
[[qw(zh zh-TW zh-Hant-TW)] => [qw(zh-Hant-TW zh-TW zh-Hant zh)]],
],
## Content negotiation
......@@ -224,10 +230,12 @@ foreach my $test (@{$tests{CanonicLang}}) {
);
}
Sympa::Language::SetLang('cs');
foreach my $test (@{$tests{ImplicatedLangs}}) {
is_deeply([Sympa::Language::ImplicatedLangs($test->[0])],
$test->[1],
"ImplicatedLangs($test->[0])" . ($test->[2] ? ": $test->[2]" : ''));
is_deeply([Sympa::Language::ImplicatedLangs(@{$test->[0]})], $test->[1],
'ImplicatedLangs('
. join(' ', @{$test->[0]}) . ')'
. ($test->[2] ? ": $test->[2]" : ''));
}
foreach my $test (@{$tests{NegotiateLang}}) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment