Commit d7fd46ab authored by sikeda's avatar sikeda
Browse files

[-bug] (Site|Robot|List)->best_language() limits languages of UI to what...

[-bug] (Site|Robot|List)->best_language() limits languages of UI to what browser requested.  List|Robot lang should be prior to them.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@8964 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent e6057ba8
......@@ -293,19 +293,6 @@ sub ImplicatedLangs {
my @implicated_langs = ();
my %implicated_langs = ();
## Workaround:
## - "zh-Hans-CN", "zh-Hant-TW", ... may occasionally be identified with
## "zh-CN", "zh-TW" etc. Add them to implication list.
@langs = map {
my $l = $_;
if ($l =~ s/^(zh)-(Hans)-(CN|SG)\b/$1-$3/i or
$l =~ s/^(zh)-(Hant)-(HK|MO|TW)\b/$1-$3/i) {
($_, $l);
} else {
($_);
}
} @langs;
foreach my $lang (@langs) {
my @subtags = CanonicLang($lang);
while (@subtags) {
......@@ -315,6 +302,19 @@ sub ImplicatedLangs {
$implicated_langs{$l} = 1;
}
## Workaround:
## - "zh-Hans-CN", "zh-Hant-TW", ... may occasionally be
## identified with "zh-CN", "zh-TW" etc. Add them to
## implication list.
if ($l =~ /^(zh)-(Hans)-(CN|SG)\b/ or
$l =~ /^(zh)-(Hant)-(HK|MO|TW)\b/) {
$l = join '-', grep {$_} @subtags[0, 2 .. $#subtags];
unless ($implicated_langs{$l}) {
push @implicated_langs, $l;
$implicated_langs{$l} = 1;
}
}
1 until pop @subtags;
}
}
......@@ -450,7 +450,7 @@ sub PopLang {
=over 4
=item SetLang ( LANG )
=item SetLang ( LANG, [ OPT =E<gt> VAL, ... ] )
I<Function>.
Sets current language along with translation catalog and locale.
......@@ -471,6 +471,7 @@ This function of Sympa 3.2a.33 or earlier returned old style "locale" names.
sub SetLang {
Log::do_log('debug2', '(%s)', @_);
my $lang = shift;
my %opts = @_;
my $locale;
## Use default lang if an empty parameter
......@@ -486,12 +487,13 @@ sub SetLang {
$locale = $lang;
} else {
unless ($lang = CanonicLang($lang) and $locale = Lang2Locale($lang)) {
Log::do_log('err', 'unknown language');
Log::do_log('err', 'unknown language')
unless $opts{'just_try'};
return undef;
}
}
unless (SetLocale($locale)) {
unless (SetLocale($locale, %opts)) {
SetLocale($current_locale || 'C'); # restore POSIX locale
return undef;
}
......@@ -509,6 +511,7 @@ sub SetLang {
sub SetLocale {
Log::do_log('debug3', '(%s)', @_);
my $locale = shift;
my %opts = @_;
## From "ll@modifier", gets "ll", "ll_RR" and "@modifier".
my ($loc, $mod) = split /(?=\@)/, $locale, 2;
......@@ -570,7 +573,8 @@ sub SetLocale {
unless (Locale::Messages::gettext('')) {
Log::do_log('err',
'Failed to bind translation catalog for locale "%s"',
$locale);
$locale
) unless $opts{'just_try'};
return undef;
}
}
......@@ -871,7 +875,6 @@ sub gettext {
}
return Locale::Messages::gettext($param[0]);
}
=over 4
......
......@@ -729,9 +729,9 @@ sub _get_topic_current_title {
}
}
if ($topic->{'title'}{'gettext'}) {
return gettext($topic->{'title'}{'gettext'});
return Language::gettext($topic->{'title'}{'gettext'});
} elsif ($topic->{'title'}{'default'}) {
return gettext($topic->{'title'}{'default'});
return Language::gettext($topic->{'title'}{'default'});
} else {
return undef;
}
......
......@@ -1077,7 +1077,7 @@ my $birthday = time ;
 
Log::set_log_level(Site->log_level);
# auto-detect browsers' lang.
Language::SetLang(Site->best_language($ENV{'HTTP_ACCEPT_LANGUAGE'}));
Language::SetLang(Site->best_language());
 
## Empty cache of the List.pm module
&List::init_list_cache();
......@@ -1496,12 +1496,15 @@ my $birthday = time ;
$param->{'list_lang'} = $list->lang
if ref $list eq 'List';
$param->{'user_lang'} = $param->{'user'}{'lang'}
if defined $param->{'user'};
$param->{'lang'} = ($list || $robot)->best_language(
if ref $param->{'user'};
foreach my $lang (
$session->{'lang'}, $param->{'user_lang'},
$ENV{'HTTP_ACCEPT_LANGUAGE'}
);
Language::SetLang($param->{'lang'});
$param->{'list_lang'}, $robot->lang, $robot->best_language()
) {
next unless $lang;
last if $param->{'lang'} = Language::SetLang(
$lang, 'just_try' => 1);
}
 
## list topics
export_topics($robot);
......@@ -1612,8 +1615,18 @@ my $birthday = time ;
$param->{'action_type'} = $action_type{$param->{'action'}};
 
$param->{'action_type'} = 'none' unless (($param->{'is_priv'})||($param->{'action_type'} eq 'serveradmin'));
$param->{'lang'} ||= $param->{'user'}{'lang'} if (defined $param->{'user'});
$param->{'lang'} ||= $robot->lang;
$param->{'user_lang'} = $param->{'user'}{'lang'}
if ref $param->{'user'};
$param->{'list_lang'} = $list->lang
if ref $list eq 'List';
foreach my $lang (
$param->{'lang'}, $param->{'user_lang'}, $param->{'list_lang'},
$robot->lang, $robot->best_language()
) {
next unless $lang;
last if $param->{'lang'} = Language::SetLang($lang, 'just_try' => 1);
}
 
if ($param->{'list'}) {
$param->{'list_title'} = $list->subject;
......@@ -3479,9 +3492,17 @@ sub do_login {
if ($session->{'lang'}) { # user did choose a specific language before being logged. Apply it as a user pref.
User::update_global_user($param->{'user'}{'email'},{lang=>$session->{'lang'}}) ;
$param->{'lang'} = $session->{'lang'};
}else{ # user did not choose a specific language, apply user pref for this session.
$param->{'lang'} = $user->{'lang'} || ($list || $robot)->lang;
$session->{'lang'} = $param->{'lang'} ;
}else{
# user did not choose a specific language, apply user pref for this
# session.
foreach my $lang (
$user->{'lang'}, ($list || $robot)->lang, $robot->best_language()
) {
next unless $lang;
last if $param->{'lang'} = Language::SetLang($lang,
'just_try' => 1);
}
$session->{'lang'} = $param->{'lang'} ;
}
 
if ($session->{'review_page_size'}) { # user did choose a specific page size upgrade prefs
......@@ -5134,8 +5155,10 @@ sub do_setpref {
}
 
## Set session language and user language to new value
if ($in{'lang'}) {
$session->{'lang'} = $robot->best_language($in{'lang'});
my $current_lang = Language::GetLang();
if ($in{'lang'} and Language::SetLang($in{'lang'})) {
$session->{'lang'} = Language::GetLang();
Language::SetLang($current_lang);
}
$param->{'lang'} = $session->{'lang'};
 
......@@ -16857,8 +16880,10 @@ sub do_search_user {
sub do_set_lang {
&wwslog('info', 'do_set_lang(%s)', $in{'lang'});
 
if ($in{'lang'}) {
$session->{'lang'} = $robot->best_language($in{'lang'});
my $current_lang = Language::GetLang();
if ($in{'lang'} and Language::SetLang($in{'lang'})) {
$session->{'lang'} = Language::GetLang();
Language::SetLang($current_lang);
}
$param->{'lang'} = $session->{'lang'};
 
......
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