summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2008-10-15 05:22:41 +0200
committerintrigeri <intrigeri@boum.org>2008-10-18 15:49:12 +0200
commit58c77a01f79efaa5692fd30231695c6f8775a7d9 (patch)
tree9195f681e3fe0767a8561c2a4f5810d5309844de /IkiWiki/Plugin
parentf42cf38076ab8fe6dcf6d9695f0950ccb61fbc01 (diff)
po plugin: create missing POT/PO files in needsbuild hook
Signed-off-by: intrigeri <intrigeri@boum.org>
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r--IkiWiki/Plugin/po.pm39
1 files changed, 28 insertions, 11 deletions
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index 98c070481..43b36430f 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -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);
}
}