po plugin[filter]: avoid converting more than once per destfile

Only the first filter function call on a given {page,destpage} must convert it
from the PO file, subsequent calls must leave the passed $content unmodified.

Else, preprocessing loops are the rule.

Signed-off-by: intrigeri <intrigeri@boum.org>
master
intrigeri 2008-10-11 03:02:43 +02:00
parent 52728bb6ea
commit 1e874b3f0a
1 changed files with 4 additions and 1 deletions

View File

@ -140,16 +140,18 @@ sub tweakbestlink ($$) { #{{{
return $link; return $link;
} #}}} } #}}}
our %filtered;
# We use filter to convert PO to the master page's type, # We use filter to convert PO to the master page's type,
# since other plugins should not work on PO files # since other plugins should not work on PO files
sub filter (@) { #{{{ sub filter (@) { #{{{
my %params = @_; my %params = @_;
my $page = $params{page}; my $page = $params{page};
my $destpage = $params{destpage};
my $content = decode_utf8(encode_utf8($params{content})); my $content = decode_utf8(encode_utf8($params{content}));
# decide if this is a PO file that should be converted into a translated document, # decide if this is a PO file that should be converted into a translated document,
# and perform various sanity checks # and perform various sanity checks
if (! istranslation($page)) { if (! istranslation($page) || $filtered{$page}{$destpage}) {
return $content; return $content;
} }
@ -174,6 +176,7 @@ sub filter (@) { #{{{
my $tmpout = $tmpfh->filename; my $tmpout = $tmpfh->filename;
$doc->write($tmpout) or error("[po/filter:$file] could not write $tmpout"); $doc->write($tmpout) or error("[po/filter:$file] could not write $tmpout");
$content = readfile($tmpout) or error("[po/filter:$file] could not read $tmpout"); $content = readfile($tmpout) or error("[po/filter:$file] could not read $tmpout");
$filtered{$page}{$destpage}=1;
return $content; return $content;
} #}}} } #}}}