X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/32cc0b336ae830831787b2024b855ed7db0a1589..a28559798ad8c60e79fe80f109dd8e63204cd208:/IkiWiki/Plugin/po.pm?ds=sidebyside diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 0c95f6c14..88985cd12 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -25,6 +25,7 @@ sub import { hook(type => "tweakbestlink", id => "po", call => \&tweakbestlink); hook(type => "filter", id => "po", call => \&filter); hook(type => "htmlize", id => "po", call => \&htmlize); + hook(type => "pagetemplate", id => "po", call => \&pagetemplate); } sub getsetup () { #{{{ @@ -198,6 +199,49 @@ sub htmlize (@) { #{{{ return IkiWiki::htmlize($page, $page, pagetype($masterfile), $content); } #}}} +sub otherlanguages ($) { #{{{ + my $page=shift; + my @ret; + if (istranslatable($page)) { + foreach my $lang (sort keys %{$translations{$page}}) { + push @ret, { + url => urlto($translations{$page}{$lang}, $page), + code => $lang, + language => $config{po_slave_languages}{$lang}, + master => 0, + }; + } + } + elsif (istranslation($page)) { + my ($masterpage, $curlang) = ($page =~ /(.*)[.]([a-z]{2})$/); + push @ret, { + url => urlto($masterpage, $page), + code => $config{po_master_language}{code}, + language => $config{po_master_language}{name}, + master => 1, + }; + foreach my $lang (sort keys %{$translations{$masterpage}}) { + push @ret, { + url => urlto($translations{$masterpage}{$lang}, $page), + code => $lang, + language => $config{po_slave_languages}{$lang}, + master => 0, + } unless ($lang eq $curlang); + } + } + return @ret; +} #}}} + +sub pagetemplate (@) { #{{{ + my %params=@_; + my $page=$params{page}; + my $template=$params{template}; + + if ($template->query(name => "otherlanguages")) { + $template->param(otherlanguages => [otherlanguages($page)]); + } +} # }}} + sub istranslatable ($) { #{{{ my $page=shift; my $file=$pagesources{$page};