diff options
author | intrigeri <intrigeri@boum.org> | 2008-11-10 14:49:58 +0100 |
---|---|---|
committer | intrigeri <intrigeri@boum.org> | 2008-11-10 14:55:21 +0100 |
commit | 5575786803b163bf10f8f6d22f958568fad40d49 (patch) | |
tree | ff132c07a9c99140468612b807069e53021cc80f /IkiWiki | |
parent | 532ec56a5f2131809f8a2709f2f1d5c1e5d0a19c (diff) |
po: abstract "doing something for the same page in every other language"
Signed-off-by: intrigeri <intrigeri@boum.org>
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/Plugin/po.pm | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index a37230b88..e7f36e968 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -138,6 +138,24 @@ sub checkconfig () { #{{{ push @{$config{wiki_file_prune_regexps}}, qr/\.pot$/; } #}}} +sub otherlanguages($) { #{{{ + my $page=shift; + + my %ret; + if (istranslatable($page)) { + %ret = %{$translations{$page}}; + } + elsif (istranslation($page)) { + my ($masterpage, $curlang) = ($page =~ /(.*)[.]([a-z]{2})$/); + $ret{$config{po_master_language}{code}} = $masterpage; + foreach my $lang (sort keys %{$translations{$masterpage}}) { + next if $lang eq $curlang; + $ret{$lang} = $translations{$masterpage}{$lang}; + } + } + return \%ret; +} #}}} + sub potfile ($) { #{{{ my $masterfile=shift; @@ -222,9 +240,7 @@ sub needsbuild () { #{{{ # make existing translations depend on the corresponding master page foreach my $master (keys %translations) { - foreach my $slave (values %{$translations{$master}}) { - add_depends($slave, $master); - } + map add_depends($_, $master), values %{otherlanguages($master)}; } } #}}} @@ -466,7 +482,7 @@ sub percenttranslated ($) { #{{{ return $percent; } #}}} -sub otherlanguages ($) { #{{{ +sub otherlanguagesloop ($) { #{{{ my $page=shift; my @ret; @@ -519,18 +535,8 @@ sub pagetemplate (@) { #{{{ $template->param(istranslatable => istranslatable($page)); } if ($template->query(name => "otherlanguages")) { - $template->param(otherlanguages => [otherlanguages($page)]); - if (istranslatable($page)) { - foreach my $translation (values %{$translations{$page}}) { - add_depends($page, $translation); - } - } - elsif (istranslation($page)) { - add_depends($page, $masterpage); - foreach my $translation (values %{$translations{$masterpage}}) { - add_depends($page, $translation) unless $page eq $translation; - } - } + $template->param(otherlanguages => [otherlanguagesloop($page)]); + map add_depends($page, $_), (values %{otherlanguages($page)}); } # Rely on IkiWiki::Render's genpage() to decide wether # a discussion link should appear on $page; this is not |