]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/po.pm
po: also filter sidebar translation pages
[ikiwiki.git] / IkiWiki / Plugin / po.pm
index 2250a7f9f309cf55d14991a17e4809af82e7eebf..6bf09b6d660cd97f76c28266ad159c2ceb930b11 100644 (file)
@@ -51,18 +51,22 @@ sub import {
        hook(type => "formbuilder_setup", id => "po", call => \&formbuilder_setup, last => 1);
        hook(type => "formbuilder", id => "po", call => \&formbuilder);
 
-       $origsubs{'bestlink'}=\&IkiWiki::bestlink;
-       inject(name => "IkiWiki::bestlink", call => \&mybestlink);
-       $origsubs{'beautify_urlpath'}=\&IkiWiki::beautify_urlpath;
-       inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
-       $origsubs{'targetpage'}=\&IkiWiki::targetpage;
-       inject(name => "IkiWiki::targetpage", call => \&mytargetpage);
-       $origsubs{'urlto'}=\&IkiWiki::urlto;
-       inject(name => "IkiWiki::urlto", call => \&myurlto);
-       $origsubs{'cgiurl'}=\&IkiWiki::cgiurl;
-       inject(name => "IkiWiki::cgiurl", call => \&mycgiurl);
-       $origsubs{'rootpage'}=\&IkiWiki::rootpage;
-       inject(name => "IkiWiki::rootpage", call => \&myrootpage);
+       if (! %origsubs) {
+               $origsubs{'bestlink'}=\&IkiWiki::bestlink;
+               inject(name => "IkiWiki::bestlink", call => \&mybestlink);
+               $origsubs{'beautify_urlpath'}=\&IkiWiki::beautify_urlpath;
+               inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
+               $origsubs{'targetpage'}=\&IkiWiki::targetpage;
+               inject(name => "IkiWiki::targetpage", call => \&mytargetpage);
+               $origsubs{'urlto'}=\&IkiWiki::urlto;
+               inject(name => "IkiWiki::urlto", call => \&myurlto);
+               $origsubs{'cgiurl'}=\&IkiWiki::cgiurl;
+               inject(name => "IkiWiki::cgiurl", call => \&mycgiurl);
+               $origsubs{'rootpage'}=\&IkiWiki::rootpage;
+               inject(name => "IkiWiki::rootpage", call => \&myrootpage);
+               $origsubs{'isselflink'}=\&IkiWiki::isselflink;
+               inject(name => "IkiWiki::isselflink", call => \&myisselflink);
+       }
 }
 
 
@@ -133,6 +137,7 @@ sub checkconfig () {
                                      $field, 'po'));
                }
        }
+       delete $config{po_slave_languages}{$config{po_master_language}{code}};;
 
        map {
                islanguagecode($_)
@@ -174,7 +179,8 @@ sub checkconfig () {
                if ($config{po_master_language}{code} ne 'en') {
                        # Add underlay containing translated source files
                        # for the master language.
-                       add_underlay("locale/$config{po_master_language}{code}/$underlay");
+                       add_underlay("locale/$config{po_master_language}{code}/$underlay")
+                               if -d "$config{underlaydirbase}/locale/$config{po_master_language}{code}/$underlay";
                }
        }
 }
@@ -237,6 +243,13 @@ sub filter (@) {
        my $page = $params{page};
        my $destpage = $params{destpage};
        my $content = $params{content};
+
+       my @caller = caller(4);
+        unless ($caller[3] eq "IkiWiki::render" ||
+                $caller[3] eq 'IkiWiki::Plugin::sidebar::sidebar_content') {
+               return $content;
+       }
+
        if (istranslation($page) && ! alreadyfiltered($page, $destpage)) {
                $content = po_to_markup($page, $content);
                setalreadyfiltered($page, $destpage);
@@ -425,8 +438,7 @@ sub change (@) {
 
        if ($updated_po_files) {
                commit_and_refresh(
-                       gettext("updated PO files"),
-                       "IkiWiki::Plugin::po::change");
+                       gettext("updated PO files"));
        }
 }
 
@@ -565,7 +577,7 @@ sub mybestlink ($$) {
        my $link=shift;
 
        return $origsubs{'bestlink'}->($page, $link)
-               if $config{po_link_to} eq "default";
+               if defined $config{po_link_to} && $config{po_link_to} eq "default";
 
        my $res=$origsubs{'bestlink'}->(masterpage($page), $link);
        my @caller = caller(1);
@@ -583,7 +595,7 @@ sub mybeautify_urlpath ($) {
        my $url=shift;
 
        my $res=$origsubs{'beautify_urlpath'}->($url);
-       if ($config{po_link_to} eq "negotiated") {
+       if (defined $config{po_link_to} && $config{po_link_to} eq "negotiated") {
                $res =~ s!/\Qindex.$config{po_master_language}{code}.$config{htmlext}\E$!/!;
                $res =~ s!/\Qindex.$config{htmlext}\E$!/!;
                map {
@@ -672,6 +684,17 @@ sub myrootpage (@) {
        return $rootpage;
 }
 
+sub myisselflink ($$) {
+       my $page=shift;
+       my $link=shift;
+
+       return 1 if $origsubs{'isselflink'}->($page, $link);
+       if (istranslation($page)) {
+               return $origsubs{'isselflink'}->(masterpage($page), $link);
+        }
+       return;
+}
+
 # ,----
 # | Blackboxes for private data
 # `----
@@ -727,6 +750,7 @@ sub istranslatablefile ($) {
        my $type=pagetype($file);
        return 0 if ! defined $type || $type eq 'po';
        return 0 if $file =~ /\.pot$/;
+       return 0 if ! defined $config{po_translatable_pages};
        return 1 if pagespec_match(pagename($file), $config{po_translatable_pages});
        return;
 }
@@ -1030,17 +1054,18 @@ sub deletetranslations ($) {
 
        if (@todelete) {
                commit_and_refresh(
-                       gettext("removed obsolete PO files"),
-                       "IkiWiki::Plugin::po::deletetranslations");
+                       gettext("removed obsolete PO files"));
        }
 }
 
-sub commit_and_refresh ($$) {
-       my ($msg, $author) = (shift, shift);
+sub commit_and_refresh ($) {
+       my $msg = shift;
 
        if ($config{rcs}) {
                IkiWiki::disable_commit_hook();
-               IkiWiki::rcs_commit_staged($msg, $author, "127.0.0.1");
+               IkiWiki::rcs_commit_staged(
+                       message => $msg,
+               );
                IkiWiki::enable_commit_hook();
                IkiWiki::rcs_update();
        }