po: added an optional target percentage to needstranslation

(cherry picked from commit 98cc9460ac)
master
intrigeri 2010-07-11 11:58:09 +02:00 committed by Joey Hess
parent 0eee3fe2a2
commit 718d9413fb
2 changed files with 19 additions and 3 deletions

View File

@ -1249,16 +1249,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 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");
}
}

View File

@ -12,7 +12,10 @@ wiki:
* "`currentlang()`" - tests whether a page is written in the same
language as the current page.
* "`needstranslation()`" - tests whether a page needs translation
work. Only slave pages match this PageSpec.
work. Only slave pages match this PageSpec. A minimum target
translation percentage can optionally be passed as an integer
parameter: "`needstranslation(50)`" matches only pages less than 50%
translated.
Note that every non-po page is considered to be written in
`po_master_language`, as specified in `ikiwiki.setup`.