X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/6fc898df75223b93eba827847fd67934a65d7bee..532ec56a5f2131809f8a2709f2f1d5c1e5d0a19c:/IkiWiki/Plugin/po.pm diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 9967e4158..a37230b88 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -202,6 +202,15 @@ sub refreshpofiles ($@) { #{{{ } } #}}} +sub buildtranslationscache() { #{{{ + # use istranslation's side-effect + map istranslation($_), (keys %pagesources); +} #}}} + +sub resettranslationscache() { #{{{ + undef %translations; +} #}}} + sub needsbuild () { #{{{ my $needsbuild=shift; @@ -209,8 +218,7 @@ sub needsbuild () { #{{{ # a given master page was rendered because its source file was changed @origneedsbuild=(@$needsbuild); - # build %translations, using istranslation's side-effect - map istranslation($_), (keys %pagesources); + buildtranslationscache(); # make existing translations depend on the corresponding master page foreach my $master (keys %translations) { @@ -335,6 +343,31 @@ sub mybestlink ($$) { #{{{ return ""; } #}}} +sub alreadyfiltered($$) { #{{{ + my $page=shift; + my $destpage=shift; + + return ( exists $filtered{$page}{$destpage} + && $filtered{$page}{$destpage} eq 1 ); +} #}}} +sub setalreadyfiltered($$) { #{{{ + my $page=shift; + my $destpage=shift; + + $filtered{$page}{$destpage}=1; +} #}}} +sub unsetalreadyfiltered($$) { #{{{ + my $page=shift; + my $destpage=shift; + + if (exists $filtered{$page}{$destpage}) { + delete $filtered{$page}{$destpage}; + } +} #}}} +sub resetalreadyfiltered() { #{{{ + undef %filtered; +} #}}} + # We use filter to convert PO to the master page's format, # since the rest of ikiwiki should not work on PO files. sub filter (@) { #{{{ @@ -345,8 +378,7 @@ sub filter (@) { #{{{ my $content = decode_utf8(encode_utf8($params{content})); return $content if ( ! istranslation($page) - || ( exists $filtered{$page}{$destpage} - && $filtered{$page}{$destpage} eq 1 )); + || alreadyfiltered($page, $destpage) ); # CRLF line terminators make poor Locale::Po4a feel bad $content=~s/\r\n/\n/g; @@ -385,16 +417,16 @@ sub filter (@) { #{{{ 'file_in_name' => \@masters, 'file_in_charset' => 'utf-8', 'file_out_charset' => 'utf-8', - ) or error("[po/filter:$infile]: failed to translate"); - $doc->write($outfile) or error("[po/filter:$infile] could not write $outfile"); - $content = readfile($outfile) or error("[po/filter:$infile] could not read $outfile"); + ) or error("[po/filter:$page]: failed to translate"); + $doc->write($outfile) or error("[po/filter:$page] could not write $outfile"); + $content = readfile($outfile) or error("[po/filter:$page] could not read $outfile"); # Unlinking should happen automatically, thanks to File::Temp, # but it does not work here, probably because of the way writefile() # and Locale::Po4a::write() work. unlink $infile, $outfile; - $filtered{$page}{$destpage}=1; + setalreadyfiltered($page, $destpage); return $content; } #}}} @@ -429,7 +461,7 @@ sub percenttranslated ($) { #{{{ 'file_in_name' => \@masters, 'file_in_charset' => 'utf-8', 'file_out_charset' => 'utf-8', - ) or error("[po/percenttranslated:$file]: failed to translate"); + ) or error("[po/percenttranslated:$page]: failed to translate"); my ($percent,$hit,$queries) = $doc->stats(); return $percent; } #}}} @@ -569,8 +601,8 @@ sub change(@) { #{{{ IkiWiki::rcs_update(); } # Reinitialize module's private variables. - undef %filtered; - undef %translations; + resetalreadyfiltered(); + resettranslationscache(); # Trigger a wiki refresh. require IkiWiki::Render; IkiWiki::refresh(); @@ -582,9 +614,7 @@ sub editcontent () { #{{{ my %params=@_; # as we're previewing or saving a page, the content may have # changed, so tell the next filter() invocation it must not be lazy - if (exists $filtered{$params{page}}{$params{page}}) { - delete $filtered{$params{page}}{$params{page}}; - } + unsetalreadyfiltered($params{page}, $params{page}); return $params{content}; } #}}}