]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/po.pm
po plugin: added [[!translatable]] directive
[ikiwiki.git] / IkiWiki / Plugin / po.pm
index 941f5629d0d0a14102c4cb9ee000a814815177f4..3546bef88a066bb747a3ea175e25a80718db515d 100644 (file)
@@ -15,6 +15,7 @@ sub import {
        hook(type => "getsetup", id => "po", call => \&getsetup);
        hook(type => "targetpage", id => "po", call => \&targetpage);
        hook(type => "filter", id => "po", call => \&filter);
+       hook(type => "preprocess", id => "translatable", call => \&preprocess_translatable);
        hook(type => "htmlize", id => "po", call => \&htmlize);
 }
 
@@ -54,18 +55,18 @@ sub targetpage (@) { #{{{
        if (IkiWiki::PageSpec::match_istranslation($page, $page)) {
                my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
                if (! $config{usedirs} || $page eq 'index') {
-                       return $masterpage . "." . $ext . "." . $lang;
+                       return $masterpage . "." . $lang . "." . $ext;
                }
                else {
-                       return $masterpage . "/index." . $ext . "." . $lang;
+                       return $masterpage . "/index." . $lang . "." . $ext;
                }
        }
        else {
                if (! $config{usedirs} || $page eq 'index') {
-                       return $page . "." . $ext . "." . $config{po_master_language}{code};
+                       return $page . "." . $config{po_master_language}{code} . "." . $ext;
                }
                else {
-                       return $page . "/index." . $ext . "." . $config{po_master_language}{code};
+                       return $page . "/index." . $config{po_master_language}{code} . "." . $ext;
                }
        }
 } #}}}
@@ -107,6 +108,17 @@ sub filter (@) { #{{{
        return $content;
 } #}}}
 
+sub preprocess_translatable (@) { #{{{
+       my %params = @_;
+       my $match = exists $params{match} ? $params{match} : $params{page};
+
+       $pagestate{$params{page}}{po_translatable}{$match}=1;
+
+       return "" if ($params{silent} && IkiWiki::yesno($params{silent}));
+       return sprintf(gettext("pages %s set as translatable"), $params{match});
+
+} #}}}
+
 sub htmlize (@) { #{{{
        my %params=@_;
        my $page = $params{page};