X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/dc74c8e5770a1b1df02a001e5c8ffd5cf1325252..886731612504bd4ac70244497b3313a20b7b6049:/IkiWiki/Plugin/po.pm?ds=inline diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 42391089b..aa592989b 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -138,14 +138,24 @@ sub needsbuild () { #{{{ istranslation($page); } + # refresh POT and PO files as needed foreach my $file (@$needsbuild) { my $page=pagename($file); - refreshpot(srcfile($file)) if (istranslatable($page)); - my @pofiles; - foreach my $lang (keys %{$translations{$page}}) { - push @pofiles, $pagesources{$translations{$page}{$lang}}; + if (istranslatable($page)) { + refreshpot(srcfile($file)); + my @pofiles; + foreach my $lang (keys %{$translations{$page}}) { + push @pofiles, $pagesources{$translations{$page}{$lang}}; + } + refreshpofiles(srcfile($file), map { srcfile($_) } @pofiles); + } + } + + # make existing translations depend on the corresponding master page + foreach my $master (keys %translations) { + foreach my $slave (values %{$translations{$master}}) { + add_depends($slave, $master); } - refreshpofiles(srcfile($file), map { srcfile($_) } @pofiles); } } #}}} @@ -362,4 +372,56 @@ sub match_istranslatable ($;@) { #{{{ } } #}}} +sub match_lang ($$;@) { #{{{ + my $page=shift; + my $wanted=shift; + my $regexp=IkiWiki::glob2re($wanted); + my $lang; + my $masterpage; + + if (IkiWiki::Plugin::po::istranslation($page)) { + ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/); + } + else { + $lang = $config{po_master_language}{code}; + } + + if ($lang!~/^$regexp$/i) { + return IkiWiki::FailReason->new("file language is $lang, not $wanted"); + } + else { + return IkiWiki::SuccessReason->new("file language is $wanted"); + } +} #}}} + +sub match_currentlang ($$;@) { #{{{ + my $page=shift; + shift; + my %params=@_; + my ($currentmasterpage, $currentlang, $masterpage, $lang); + + return IkiWiki::FailReason->new("no location provided") unless exists $params{location}; + + if (IkiWiki::Plugin::po::istranslation($params{location})) { + ($currentmasterpage, $currentlang) = ($params{location} =~ /(.*)[.]([a-z]{2})$/); + } + else { + $currentlang = $config{po_master_language}{code}; + } + + if (IkiWiki::Plugin::po::istranslation($page)) { + ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/); + } + else { + $lang = $config{po_master_language}{code}; + } + + if ($lang eq $currentlang) { + return IkiWiki::SuccessReason->new("file language is the same as current one, i.e. $currentlang"); + } + else { + return IkiWiki::FailReason->new("file language is $lang, whereas current language is $currentlang"); + } +} #}}} + 1