]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/po.pm
po/todo: first pass of robustness tests, added todo for remove/rename
[git.ikiwiki.info.git] / IkiWiki / Plugin / po.pm
index 03ee9c33c15ab80fa1946ca17d0c902e33acbd8c..1212181ca39b5747cbc9ac635e66f1af6ea885c8 100644 (file)
@@ -262,10 +262,14 @@ sub htmlize (@) { #{{{
 
        my $page = $params{page};
        my $content = $params{content};
 
        my $page = $params{page};
        my $content = $params{content};
-       my $masterfile = srcfile($pagesources{masterpage($page)});
+
+       # ignore PO files this plugin did not create
+       return $content unless istranslation($page);
 
        # force content to be htmlize'd as if it was the same type as the master page
 
        # force content to be htmlize'd as if it was the same type as the master page
-       return IkiWiki::htmlize($page, $page, pagetype($masterfile), $content);
+       return IkiWiki::htmlize($page, $page,
+                               pagetype(srcfile($pagesources{masterpage($page)})),
+                               $content);
 } #}}}
 
 sub pagetemplate (@) { #{{{
 } #}}}
 
 sub pagetemplate (@) { #{{{
@@ -391,11 +395,9 @@ sub mybestlink ($$) { #{{{
        my $link=shift;
 
        my $res=$origsubs{'bestlink'}->(masterpage($page), $link);
        my $link=shift;
 
        my $res=$origsubs{'bestlink'}->(masterpage($page), $link);
-       my $normres=$res;
-       $normres=~s#^/##;
        if (length $res
            && ($config{po_link_to} eq "current" || $config{po_link_to} eq "negotiated")
        if (length $res
            && ($config{po_link_to} eq "current" || $config{po_link_to} eq "negotiated")
-           && istranslatable($normres)
+           && istranslatable($res)
            && istranslation($page)) {
                return $res . "." . lang($page);
        }
            && istranslation($page)) {
                return $res . "." . lang($page);
        }
@@ -488,9 +490,18 @@ sub myurlto ($$;$) { #{{{
 # | Helper functions
 # `----
 
 # | Helper functions
 # `----
 
+sub maybe_add_leading_slash ($;$) { #{{{
+       my $str=shift;
+       my $add=shift;
+       $add=1 unless defined $add;
+       return '/' . $str if $add;
+       return $str;
+} #}}}
+
 sub istranslatable ($) { #{{{
        my $page=shift;
 
 sub istranslatable ($) { #{{{
        my $page=shift;
 
+       $page=~s#^/##;
        my $file=$pagesources{$page};
 
        return 0 unless defined $file;
        my $file=$pagesources{$page};
 
        return 0 unless defined $file;
@@ -502,6 +513,7 @@ sub istranslatable ($) { #{{{
 sub _istranslation ($) { #{{{
        my $page=shift;
 
 sub _istranslation ($) { #{{{
        my $page=shift;
 
+       my $hasleadingslash = ($page=~s#^/##);
        my $file=$pagesources{$page};
        return 0 unless (defined $file
                         && defined pagetype($file)
        my $file=$pagesources{$page};
        return 0 unless (defined $file
                         && defined pagetype($file)
@@ -514,15 +526,18 @@ sub _istranslation ($) { #{{{
                         && defined $pagesources{$masterpage}
                         && defined $config{po_slave_languages}{$lang});
 
                         && defined $pagesources{$masterpage}
                         && defined $config{po_slave_languages}{$lang});
 
-       return ($masterpage, $lang) if istranslatable($masterpage);
+       return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang)
+               if istranslatable($masterpage);
 } #}}}
 
 sub istranslation ($) { #{{{
        my $page=shift;
 
        if (1 < (my ($masterpage, $lang) = _istranslation($page))) {
 } #}}}
 
 sub istranslation ($) { #{{{
        my $page=shift;
 
        if (1 < (my ($masterpage, $lang) = _istranslation($page))) {
+               my $hasleadingslash = ($masterpage=~s#^/##);
                $translations{$masterpage}{$lang}=$page unless exists $translations{$masterpage}{$lang};
                $translations{$masterpage}{$lang}=$page unless exists $translations{$masterpage}{$lang};
-               return ($masterpage, $lang);
+               return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang)
+                       if istranslatable($masterpage);
        }
        return;
 } #}}}
        }
        return;
 } #}}}