]> sipb.mit.edu Git - ikiwiki.git/commitdiff
po plugin: create missing POT/PO files in needsbuild hook
authorintrigeri <intrigeri@boum.org>
Wed, 15 Oct 2008 03:22:41 +0000 (05:22 +0200)
committerintrigeri <intrigeri@boum.org>
Sat, 18 Oct 2008 13:49:12 +0000 (15:49 +0200)
Signed-off-by: intrigeri <intrigeri@boum.org>
IkiWiki/Plugin/po.pm
doc/plugins/po.mdwn

index 98c070481978a560d328ecc107dac4396d3a341e..43b36430f7267cd3abb5d808185971c376be285a 100644 (file)
@@ -96,10 +96,22 @@ sub checkconfig () { #{{{
        push @{$config{wiki_file_prune_regexps}}, qr/\.pot$/;
 } #}}}
 
-sub refreshpot ($) { #{{{
+sub potfile ($) { #{{{
+       my $masterfile=shift;
+       (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/);
+       return File::Spec->catfile($dir, $name . ".pot");
+} #}}}
+
+sub pofile ($$) { #{{{
        my $masterfile=shift;
+       my $lang=shift;
        (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/);
-       my $potfile=File::Spec->catfile($dir, $name . ".pot");
+       return File::Spec->catfile($dir, $name . "." . $lang . ".po");
+} #}}}
+
+sub refreshpot ($) { #{{{
+       my $masterfile=shift;
+       my $potfile=potfile($masterfile);
        my %options = ("markdown" => (pagetype($masterfile) eq 'mdwn') ? 1 : 0);
        my $doc=Locale::Po4a::Chooser::new('text',%options);
        $doc->read($masterfile);
@@ -114,8 +126,7 @@ sub refreshpofiles ($@) { #{{{
        my $masterfile=shift;
        my @pofiles=@_;
 
-       (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/);
-       my $potfile=File::Spec->catfile($dir, $name . ".pot");
+       my $potfile=potfile($masterfile);
        error("[po/refreshpofiles] POT file ($potfile) does not exist") unless (-e $potfile);
 
        foreach my $pofile (@pofiles) {
@@ -139,16 +150,22 @@ sub needsbuild () { #{{{
                istranslation($page);
        }
 
-       # refresh POT and PO files as needed
-       foreach my $file (@$needsbuild) {
-               my $page=pagename($file);
+       # refresh/create POT and PO files as needed
+       foreach my $page (keys %pagesources) {
+               my $pageneedsbuild = grep { $_ eq $pagesources{$page} } @$needsbuild;
                if (istranslatable($page)) {
-                       refreshpot(srcfile($file));
+                       my $file=srcfile($pagesources{$page});
+                       if ($pageneedsbuild || ! -e potfile($file)) {
+                               refreshpot($file);
+                       }
                        my @pofiles;
-                       foreach my $lang (keys %{$translations{$page}}) {
-                               push @pofiles, $pagesources{$translations{$page}{$lang}};
+                       foreach my $lang (keys %{$config{po_slave_languages}}) {
+                               my $pofile=pofile($file, $lang);
+                               if ($pageneedsbuild || ! -e $pofile) {
+                                       push @pofiles, $pofile;
+                               }
                        }
-                       refreshpofiles(srcfile($file), map { srcfile($_) } @pofiles);
+                       refreshpofiles($file, @pofiles) if (@pofiles);
                }
        }
 
index 4e7553a11c43fb053f03026dc53e91c55bfc566e..ab7fcb725ee228cf82a1dae22f41e4652481f998 100644 (file)
@@ -197,11 +197,11 @@ Committing changes to a "master" page:
    achieved by making any "slave" page dependent on the corresponding
    "master" page, in the `needsbuild` hook.
 
-**FIXME** Also, when the plugin has just been enabled, or when a page
+Also, when the plugin has just been enabled, or when a page
 has just been declared as being translatable:
 
-- all the needed POT and PO files have to be created
-- the PO files must be checked into version control
+- all the needed POT and PO files are be created
+- **FIXME** the PO files must be checked into version control
 
 **FIXME** `refreshpofiles` uses `system()`, whose args have to be
 checked more thoroughly to prevent any security issue (command