]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/po.pm
po plugin: added currentlang() custom PageSpec function
[git.ikiwiki.info.git] / IkiWiki / Plugin / po.pm
index ca26101b7c52c9a1a4d6b7ce38e0100196eccea0..aa592989b659497070bcf0fc659a785e1c15921a 100644 (file)
@@ -150,6 +150,13 @@ sub needsbuild () { #{{{
                        refreshpofiles(srcfile($file), map { srcfile($_) } @pofiles);
                }
        }
                        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);
+               }
+       }
 } #}}}
 
 sub targetpage (@) { #{{{
 } #}}}
 
 sub targetpage (@) { #{{{
@@ -365,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
 1