Commit 06a1e037 authored by sikeda's avatar sikeda
Browse files

[-feature] Use canonic lang to get titles of task, scenarios and list topics,...

[-feature] Use canonic lang to get titles of task, scenarios and list topics, with fallbacking over implicated languages.
- "title.<lang>" lines in scenario files are available again, though this feature was broken for a while.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@8961 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent abb75bbd
......@@ -5494,19 +5494,13 @@ sub get_scenario {
}
sub load_task_list {
my ($self, $action, $robot) = @_;
&Log::do_log('debug2', 'List::load_task_list(%s,%s)', $action, $robot);
Log::do_log('debug2', '(%s, %s)', @_);
my $self = shift;
my $action = shift;
my $directory = $self->dir;
my %list_of_task;
foreach my $dir (
"$directory/list_task_models",
Site->etc . "/$robot/list_task_models",
Site->etc . "/list_task_models",
Sympa::Constants::DEFAULTDIR . '/list_task_models'
) {
foreach my $dir (@{$self->get_etc_include_path('list_task_models')}) {
next unless (-d $dir);
foreach my $file (<$dir/$action.*>) {
......@@ -5517,16 +5511,20 @@ sub load_task_list {
$list_of_task{$name}{'name'} = $name;
my $titles = &List::_load_task_title($file);
my $titles = List::_load_task_title($file);
## Set the title in the current language
if (defined $titles->{&Language::GetLang()}) {
$list_of_task{$name}{'title'} =
$titles->{&Language::GetLang()};
} elsif (defined $titles->{'gettext'}) {
foreach my $lang (Language::ImplicatedLangs()) {
if (defined $titles->{$lang}) {
$list_of_task{$name}{'title'} = $titles->{$lang};
last;
}
}
next if defined $list_of_task{$name}{'title'};
if (defined $titles->{'gettext'}) {
$list_of_task{$name}{'title'} = gettext($titles->{'gettext'});
} elsif (defined $titles->{'us'}) {
$list_of_task{$name}{'title'} = gettext($titles->{'us'});
$list_of_task{$name}{'title'} = $titles->{'us'};
} else {
$list_of_task{$name}{'title'} = $name;
}
......@@ -5538,20 +5536,28 @@ sub load_task_list {
}
sub _load_task_title {
Log::do_log('debug3', '(%s)', @_);
my $file = shift;
&Log::do_log('debug3', 'List::_load_task_title(%s)', $file);
my $title = {};
unless (open TASK, $file) {
&Log::do_log('err', 'Unable to open file "%s"', $file);
Log::do_log('err', 'Unable to open file "%s": %s', $file, $!);
return undef;
}
while (<TASK>) {
last if /^\s*$/;
if (/^title\.([\w-]+)\s+(.*)\s*$/) {
$title->{$1} = $2;
if (/^title\.gettext\s+(.*)\s*$/) {
$title->{'gettext'} = $1;
} elsif (/^title\.us\s+(.*)\s*$/) {
$title->{'us'} = $1;
} elsif (/^title\.([-.\w]+)\s+(.*)\s*$/) {
my ($lang, $t) = ($1, $2);
$lang = Language::CanonicLang($lang) || $lang;
$title->{$lang} = $t;
} elsif (/^title\s+(\S.*?)\s*$/) { # new on 6.2a.34.
$title->{'us'} = $1;
}
}
......
......@@ -687,18 +687,13 @@ sub topics {
$list_of_topics = tools::dup_var($self->{'topics'});
## Set the title in the current language
my $lang = Language::GetLang();
foreach my $top (keys %{$list_of_topics}) {
my $topic = $list_of_topics->{$top};
$topic->{'current_title'} = $topic->{'title'}{$lang} ||
$topic->{'title'}{'default'} ||
$top;
$topic->{'current_title'} = _get_topic_current_title($topic) || $top;
foreach my $subtop (keys %{$topic->{'sub'}}) {
$topic->{'sub'}{$subtop}{'current_title'} =
$topic->{'sub'}{$subtop}{'title'}{$lang} ||
$topic->{'sub'}{$subtop}{'title'}{'default'} ||
$subtop;
_get_topic_current_title($topic->{'sub'}{$subtop}) || $subtop;
}
}
......@@ -712,6 +707,13 @@ sub _get_topic_titles {
foreach my $key (%{$topic}) {
if ($key =~ /^title(.(\w+))?$/) {
my $lang = $2 || 'default';
if ($lang eq 'gettext') { # new in 6.2a.34
;
} elsif ($lang eq 'default') {
;
} else {
$lang = Language::CanonicLang($lang) || $lang;
}
$title->{$lang} = $topic->{$key};
}
}
......@@ -719,6 +721,22 @@ sub _get_topic_titles {
return $title;
}
sub _get_topic_current_title {
my $topic = shift;
foreach my $lang (Language::ImplicatedLangs()) {
if ($topic->{'title'}{$lang}) {
return $topic->{'title'}{$lang};
}
}
if ($topic->{'title'}{'gettext'}) {
return gettext($topic->{'title'}{'gettext'});
} elsif ($topic->{'title'}{'default'}) {
return gettext($topic->{'title'}{'default'});
} else {
return undef;
}
}
## Inner sub used by load_topics()
sub _add_topic {
my ($name, $title) = @_;
......
......@@ -248,9 +248,8 @@ sub _parse_scenario {
next;
} elsif ($current_rule =~ /^\s*title\.([-.\w]+)\s+(.*)\s*$/i) {
my ($lang, $title) = ($1, $2);
Language::PushLang($lang);
$structure->{'title'}{Language::GetLang()} = $title;
Language::PopLang();
$lang = Language::CanonicLang($lang) || $lang;
$structure->{'title'}{$lang} = $title;
next;
} elsif ($current_rule =~ /^\s*title\s+(.*)\s*$/i) {
$structure->{'title'}{'us'} = $1;
......@@ -1810,9 +1809,12 @@ Get internationalized title of the scenario, under current language context.
sub get_current_title {
my $self = shift;
if (defined $self->{'title'}{Language::GetLang()}) {
return $self->{'title'}{Language::GetLang()};
} elsif (defined $self->{'title'}{'gettext'}) {
foreach my $lang (Language::ImplicatedLangs()) {
if (defined $self->{'title'}{$lang}) {
return $self->{'title'}{$lang};
}
}
if (defined $self->{'title'}{'gettext'}) {
return Language::gettext($self->{'title'}{'gettext'});
} elsif (defined $self->{'title'}{'us'}) {
return Language::gettext($self->{'title'}{'us'});
......@@ -1849,7 +1851,8 @@ Returns 1 if all conditions in scenario are "true() [an_auth_method] -> re
sub is_purely_closed {
my $self = shift;
foreach my $rule (@{$self->{'rules'}}) {
if ($rule->{'condition'} ne 'true' && $rule->{'action'} !~ /reject/) {
if ($rule->{'condition'} ne 'true' &&
$rule->{'action'} !~ /reject/) {
Log::do_log('debug2', 'Scenario %s is not purely closed.',
$self->{'title'});
return 0;
......
......@@ -103,6 +103,8 @@ Creates a list. Used by the create_list() sub in sympa.pl and the do_create_list
=head3 Calls
=over 4
=item * check_owner_defined
=item * install_aliases
......
......@@ -3218,8 +3218,6 @@ Clean all messages in spool $spool_dir older than $clean_delay.
=back
=back
=head3 Return
=over
......
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