summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2008-10-14 17:17:24 +0200
committerintrigeri <intrigeri@boum.org>2008-10-18 15:49:11 +0200
commit6424d748a4da431c244d0775d4d4e839fdd3f671 (patch)
tree679067e777663ede2551862db39461704c58a1a6 /IkiWiki/Plugin
parentd5b5cfb8e42b7fed8a2a777c542461c0bcebf5ea (diff)
po plugin: refresh PO files when a master page is updated
Signed-off-by: intrigeri <intrigeri@boum.org>
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/po.pm30
1 files changed, 29 insertions, 1 deletions
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index 1cab44dde..900ca90e4 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -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);
}
} #}}}