]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/po.pm
po plugin: refresh PO files when a master page is updated
[ikiwiki.git] / IkiWiki / Plugin / po.pm
index 1cab44dde10e4a227df82f6ac81ead3229c4d609..900ca90e4ba6c22b66d1b10a99538f6747a93766 100644 (file)
@@ -10,6 +10,7 @@ use IkiWiki 2.00;
 use Encode;
 use Locale::Po4a::Chooser;
 use File::Basename;
+use File::Copy;
 use File::Spec;
 use File::Temp;
 use Memoize;
@@ -108,6 +109,27 @@ sub refreshpot ($) { #{{{
        $doc->writepo($potfile);
 } #}}}
 
+sub refreshpofiles ($@) { #{{{
+       my $masterfile=shift;
+       my @pofiles=@_;
+
+       (my $name, my $dir, my $suffix) = fileparse($masterfile, qr/\.[^.]*/);
+       my $potfile=File::Spec->catfile($dir, $name . ".pot");
+       error("[po/refreshpofiles] POT file ($potfile) does not exist") unless (-e $potfile);
+
+       foreach my $pofile (@pofiles) {
+               if (-e $pofile) {
+                       my $cmd = "msgmerge -U $pofile $potfile";
+                       system ($cmd) == 0
+                               or error("[po/refreshpofiles:$pofile] failed to update");
+               }
+               else {
+                       File::Copy::syscopy($potfile,$pofile)
+                               or error("[po/refreshpofiles:$pofile] failed to copy the POT file");
+               }
+       }
+} #}}}
+
 sub needsbuild () { #{{{
        my $needsbuild=shift;
 
@@ -117,7 +139,13 @@ sub needsbuild () { #{{{
        }
 
        foreach my $file (@$needsbuild) {
-               refreshpot(srcfile($file)) if (istranslatable(pagename($file)));
+               my $page=pagename($file);
+               refreshpot(srcfile($file)) if (istranslatable($page));
+               my @pofiles;
+               foreach my $lang (keys %{$translations{$page}}) {
+                       push @pofiles, $pagesources{$translations{$page}{$lang}};
+               }
+               refreshpofiles(srcfile($file), map { srcfile($_) } @pofiles);
        }
 } #}}}