po: added a needstranslation() pagespec
[ikiwiki.git] / IkiWiki / Plugin / po.pm
index 7d5dfee03f480fc039b66c54a34d5e1a1a7b111b..552b6b51bea28a676639f91c584a98767238f277 100644 (file)
@@ -259,11 +259,9 @@ sub filter (@) {
        my $page = $params{page};
        my $destpage = $params{destpage};
        my $content = $params{content};
+       my $fullpage = $params{fullpage};
 
-       my @caller = caller(4);
-       # FIXME: need to whitelist inline as well?
-        unless ($caller[3] eq "IkiWiki::render" ||
-                $caller[3] eq 'IkiWiki::Plugin::sidebar::sidebar_content') {
+       unless ($fullpage) {
                return $content;
        }
 
@@ -902,15 +900,15 @@ sub refreshpot ($) {
        my $doc=Locale::Po4a::Chooser::new(po4a_type($masterfile),
                                           po4a_options($masterfile));
        $doc->{TT}{utf_mode} = 1;
-       $doc->{TT}{file_in_charset} = 'utf-8';
-       $doc->{TT}{file_out_charset} = 'utf-8';
+       $doc->{TT}{file_in_charset} = 'UTF-8';
+       $doc->{TT}{file_out_charset} = 'UTF-8';
        $doc->read($masterfile);
        # let's cheat a bit to force porefs option to be passed to
        # Locale::Po4a::Po; this is undocument use of internal
        # Locale::Po4a::TransTractor's data, compulsory since this module
        # prevents us from using the porefs option.
        $doc->{TT}{po_out}=Locale::Po4a::Po->new({ 'porefs' => 'none' });
-       $doc->{TT}{po_out}->set_charset('utf-8');
+       $doc->{TT}{po_out}->set_charset('UTF-8');
        # do the actual work
        $doc->parse;
        IkiWiki::prep_writefile(basename($potfile),dirname($potfile));
@@ -996,8 +994,8 @@ sub percenttranslated ($) {
        $doc->process(
                'po_in_name'    => [ $file ],
                'file_in_name'  => [ $masterfile ],
-               'file_in_charset'  => 'utf-8',
-               'file_out_charset' => 'utf-8',
+               'file_in_charset'  => 'UTF-8',
+               'file_out_charset' => 'UTF-8',
        ) or error("po(percenttranslated) ".
                   sprintf(gettext("failed to translate %s"), $page));
        my ($percent,$hit,$queries) = $doc->stats();
@@ -1143,8 +1141,8 @@ sub po_to_markup ($$) {
        $doc->process(
                'po_in_name'    => [ $infile ],
                'file_in_name'  => [ $masterfile ],
-               'file_in_charset'  => 'utf-8',
-               'file_out_charset' => 'utf-8',
+               'file_in_charset'  => 'UTF-8',
+               'file_out_charset' => 'UTF-8',
        ) or return $fail->(gettext("failed to translate"));
        $doc->write($outfile)
                or return $fail->(sprintf(gettext("failed to write %s"), $outfile));
@@ -1293,4 +1291,19 @@ sub match_currentlang ($$;@) {
        }
 }
 
+sub match_needstranslation ($$;@) {
+       my $page=shift;
+
+       my $percenttranslated=IkiWiki::Plugin::po::percenttranslated($page);
+       if ($percenttranslated eq 'N/A') {
+               return IkiWiki::FailReason->new("file is not a translation page");
+       }
+       elsif ($percenttranslated < 100) {
+               return IkiWiki::SuccessReason->new("file has $percenttranslated translated");
+        }
+       else {
+               return IkiWiki::FailReason->new("file is fully translated");
+       }
+}
+
 1