X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/c9b1a4dd7d826b5e8e2d0a757ba5ecbba8d832b2..e5f67d3c8bd59ff715e2d71c3b4747aa11c61085:/IkiWiki/Plugin/po.pm diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 29945da33..1f3ff252e 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -28,7 +28,7 @@ use UNIVERSAL; my %translations; my @origneedsbuild; my %origsubs; -my @slavelanguages; # orderer as in config po_slave_languages +my @slavelanguages; # languages codes ordered as in config po_slave_languages memoize("istranslatable"); memoize("_istranslation"); @@ -106,10 +106,10 @@ sub getsetup () { po_slave_languages => { type => "string", example => [ - 'fr' => 'Français', - 'es' => 'Español', - 'de' => 'Deutsch' - ], + 'fr|Français', + 'es|Español', + 'de|Deutsch' + ], description => "slave languages (PO files)", safe => 1, rebuild => 1, @@ -141,9 +141,15 @@ sub checkconfig () { if (ref $config{po_slave_languages} eq 'ARRAY') { my %slaves; - for (my $i=0; $i<@{$config{po_slave_languages}}; $i = $i + 2) { - $slaves{$config{po_slave_languages}->[$i]} = $config{po_slave_languages}->[$i + 1]; - push @slavelanguages, $config{po_slave_languages}->[$i]; + foreach my $pair (@{$config{po_slave_languages}}) { + my ($code, $name) = ( $pair =~ /^([a-z]{2})\|(.+)$/ ); + if (!defined $code || !defined $name) { + error(sprintf(gettext("%s has invalid syntax: must use CODE|NAME"), + $pair)); + } + $slaves{$code} = $name; + push @slavelanguages, $code; + } $config{po_slave_languages} = \%slaves; } @@ -259,12 +265,6 @@ sub filter (@) { my $page = $params{page}; my $destpage = $params{destpage}; my $content = $params{content}; - my $fullpage = $params{fullpage}; - - unless ($fullpage) { - return $content; - } - if (istranslation($page) && ! alreadyfiltered($page, $destpage)) { $content = po_to_markup($page, $content); setalreadyfiltered($page, $destpage); @@ -852,7 +852,7 @@ sub otherlanguages_codes ($) { return \@ret unless istranslation($page) || istranslatable($page); my $curlang=lang($page); foreach my $lang - ($config{po_master_language}{code}, @slavelanguages) { + ($config{po_master_language}{code}, keys %{$config{po_slave_languages}}) { next if $lang eq $curlang; push @ret, $lang; } @@ -1293,16 +1293,29 @@ sub match_currentlang ($$;@) { sub match_needstranslation ($$;@) { my $page=shift; + my $wanted=shift; + + if (defined $wanted && $wanted ne "") { + if ($wanted !~ /^\d+$/) { + return IkiWiki::FailReason->new("parameter is not an integer"); + } + elsif ($wanted > 100) { + return IkiWiki::FailReason->new("parameter is greater than 100"); + } + } + else { + $wanted=100; + } my $percenttranslated=IkiWiki::Plugin::po::percenttranslated($page); if ($percenttranslated eq 'N/A') { - return IkiWiki::FailReason->new("file is not a translation page"); + return IkiWiki::FailReason->new("file is not a translatable page"); } - elsif ($percenttranslated < 100) { + elsif ($percenttranslated < $wanted) { return IkiWiki::SuccessReason->new("file has $percenttranslated translated"); } else { - return IkiWiki::FailReason->new("file is fully translated"); + return IkiWiki::FailReason->new("file is translated enough"); } }