]> scripts.mit.edu Git - www/ikiwiki.git/blobdiff - IkiWiki/Plugin/po.pm
po(nicepagetitle): forgot to display %
[www/ikiwiki.git] / IkiWiki / Plugin / po.pm
index 515809f70dfd99ad334cb32d32db7cc8d22c6fd5..cee7a7654c152264ec33bd4c16384eac875a0971 100644 (file)
@@ -48,6 +48,8 @@ sub import { #{{{
        inject(name => "IkiWiki::targetpage", call => \&mytargetpage);
        $origsubs{'urlto'}=\&IkiWiki::urlto;
        inject(name => "IkiWiki::urlto", call => \&myurlto);
+       $origsubs{'nicepagetitle'}=\&IkiWiki::nicepagetitle;
+       inject(name => "IkiWiki::nicepagetitle", call => \&mynicepagetitle);
 } #}}}
 
 
@@ -465,9 +467,33 @@ sub myurlto ($$;$) { #{{{
            && istranslatable('index')) {
                return IkiWiki::beautify_urlpath(IkiWiki::baseurl($from) . "index." . lang($from) . ".$config{htmlext}");
        }
-       return $origsubs{'urlto'}->($to,$from,$absolute);
+       # avoid using our injected beautify_urlpath if run by cgi_editpage,
+       # so that one is redirected to the just-edited page rather than to the
+       # negociated translation; to prevent unnecessary fiddling with caller/inject,
+       # we only do so when our beautify_urlpath would actually do what we want to
+       # avoid, i.e. when po_link_to = negotiated
+       if ($config{po_link_to} eq "negotiated") {
+               my @caller = caller(1);
+               my $run_by_editpage = ($caller[3] eq "IkiWiki::cgi_editpage");
+               inject(name => "IkiWiki::beautify_urlpath", call => $origsubs{'beautify_urlpath'})
+                       if $run_by_editpage;
+               my $res = $origsubs{'urlto'}->($to,$from,$absolute);
+               inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath)
+                       if $run_by_editpage;
+               return $res;
+       }
+       else {
+               return $origsubs{'urlto'}->($to,$from,$absolute)
+       }
 } #}}}
 
+sub mynicepagetitle ($;$) { #{{{
+       my ($page, $unescaped) = (shift, shift);
+
+       my $res = $origsubs{'nicepagetitle'}->($page, $unescaped);
+       return $res unless istranslation($page);
+       return $res.' ('.percenttranslated($page).' %)';
+} #}}}
 
 # ,----
 # | Blackboxes for private data
@@ -706,6 +732,7 @@ sub urlto_with_orig_beautiful_urlpath($$) { #{{{
 sub percenttranslated ($) { #{{{
        my $page=shift;
 
+       $page=~s/^\///;
        return gettext("N/A") unless istranslation($page);
        my $file=srcfile($pagesources{$page});
        my $masterfile = srcfile($pagesources{masterpage($page)});