X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/1e874b3f0a396ba99ebf7ab8bad3d7eed1a846f2..32cc0b336ae830831787b2024b855ed7db0a1589:/IkiWiki/Plugin/po.pm diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 0698b2488..0c95f6c14 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -10,6 +10,11 @@ use IkiWiki 2.00; use Encode; use Locale::Po4a::Chooser; use File::Temp; +use Memoize; + +my %translations; +memoize("istranslatable"); +memoize("_istranslation"); sub import { hook(type => "getsetup", id => "po", call => \&getsetup); @@ -40,9 +45,10 @@ sub getsetup () { #{{{ }, po_slave_languages => { type => "string", - example => {'fr' => { 'name' => 'Français' }, - 'es' => { 'name' => 'Castellano' }, - 'de' => { 'name' => 'Deutsch' }, + example => { + 'fr' => 'Français', + 'es' => 'Castellano', + 'de' => 'Deutsch' }, description => "slave languages (PO files)", safe => 1, @@ -88,9 +94,10 @@ sub checkconfig () { #{{{ sub scan (@) { #{{{ my %params=@_; my $page=$params{page}; - - # FIXME: cache (or memoize) the list of translatable/translation pages, - # and/or istranslation/istranslated results + # let's build %translations, using istranslation's + # side-effect, so that we can consider it is complete at + # preprocess time + istranslation($page); } #}}} sub targetpage (@) { #{{{ @@ -203,7 +210,7 @@ sub istranslatable ($) { #{{{ return pagespec_match($page, $config{po_translatable_pages}); } #}}} -sub istranslation ($) { #{{{ +sub _istranslation ($) { #{{{ my $page=shift; my $file=$pagesources{$page}; if (! defined $file) { @@ -228,6 +235,15 @@ sub istranslation ($) { #{{{ return istranslatable($masterpage); } #}}} +sub istranslation ($) { #{{{ + my $page=shift; + if (_istranslation($page)) { + my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/); + $translations{$masterpage}{$lang}=$page unless exists $translations{$masterpage}{$lang}; + return 1; + } + return 0; +} #}}} package IkiWiki::PageSpec; use warnings;