]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/po.pm
po: inject custom isselflink to fix selflink detection on translation pages
[git.ikiwiki.info.git] / IkiWiki / Plugin / po.pm
index 5d0d9e79dd26074344a642f524d098101e4a21c8..bbbb3b870ad5d31db565349a185174824879d025 100644 (file)
@@ -63,6 +63,8 @@ sub import {
        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);
 }
 
 
@@ -386,31 +388,32 @@ sub change (@) {
                resetalreadyfiltered();
                require IkiWiki::Render;
                foreach my $file (@rendered) {
-                       debug(sprintf(gettext("building %s"), $file));
-                       IkiWiki::render($file);
+                       IkiWiki::render($file, sprintf(gettext("building %s"), $file));
                }
        }
 
        my $updated_po_files=0;
 
        # Refresh/create POT and PO files as needed.
-       # (But avoid doing so if they are in an underlay directory.)
        foreach my $file (grep {istranslatablefile($_)} @rendered) {
                my $masterfile=srcfile($file);
                my $page=pagename($file);
                my $updated_pot_file=0;
+
+               # Avoid touching underlay files.
+               next if $masterfile ne "$config{srcdir}/$file";
+
                # Only refresh POT file if it does not exist, or if
-               # $pagesources{$page} was changed: don't if only the HTML was
+               # the source was changed: don't if only the HTML was
                # refreshed, e.g. because of a dependency.
-               if ($masterfile eq "$config{srcdir}/$file" &&
-                  ((grep { $_ eq $pagesources{$page} } @origneedsbuild)
-                   || ! -e potfile($masterfile))) {
+               if ((grep { $_ eq $pagesources{$page} } @origneedsbuild) ||
+                   ! -e potfile($masterfile)) {
                        refreshpot($masterfile);
                        $updated_pot_file=1;
                }
                my @pofiles;
                foreach my $po (pofiles($masterfile)) {
-                       next if ! $updated_pot_file && -e $po;
+                       next if ! $updated_pot_file && -e $po;
                        next if grep { $po=~/\Q$_\E/ } @{$config{underlaydirs}};
                        push @pofiles, $po;
                }
@@ -670,6 +673,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
 # `----