]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/po.pm
minor layout changes
[git.ikiwiki.info.git] / IkiWiki / Plugin / po.pm
index 59d938d821151a1f9f0ec3bac27c1a18f8c406ec..4bac376561139cbf6077276b9e89a7198c2201ca 100644 (file)
@@ -31,7 +31,7 @@ $origsubs{'bestlink'}=\&IkiWiki::bestlink;
 $origsubs{'beautify_urlpath'}=\&IkiWiki::beautify_urlpath;
 $origsubs{'targetpage'}=\&IkiWiki::targetpage;
 
-sub import {
+sub import { #{{{
        hook(type => "getsetup", id => "po", call => \&getsetup);
        hook(type => "checkconfig", id => "po", call => \&checkconfig);
        hook(type => "needsbuild", id => "po", call => \&needsbuild);
@@ -41,13 +41,13 @@ sub import {
        inject(name => "IkiWiki::bestlink", call => \&mybestlink);
        inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
        inject(name => "IkiWiki::targetpage", call => \&mytargetpage);
-}
+} #}}}
 
 sub getsetup () { #{{{
        return
                plugin => {
                        safe => 0,
-                       rebuild => 1, # format plugin
+                       rebuild => 1, # format plugin & changes html filenames
                },
                po_master_language => {
                        type => "string",
@@ -149,8 +149,7 @@ sub refreshpofiles ($@) { #{{{
 
        foreach my $pofile (@pofiles) {
                if (-e $pofile) {
-                       my $cmd = "msgmerge -U --backup=none $pofile $potfile";
-                       system ($cmd) == 0
+                       system("msgmerge", "-U", "--backup=none", $pofile, $potfile) == 0
                                or error("[po/refreshpofiles:$pofile] failed to update");
                }
                else {
@@ -204,8 +203,8 @@ sub needsbuild () { #{{{
                IkiWiki::refresh();
                IkiWiki::saveindex();
                # refresh module's private variables
-               %filtered=undef;
-               %translations=undef;
+               undef %filtered;
+               undef %translations;
                foreach my $page (keys %pagesources) {
                        istranslation($page);
                }
@@ -290,8 +289,8 @@ sub filter (@) { #{{{
        my $destpage = $params{destpage};
        my $content = decode_utf8(encode_utf8($params{content}));
 
-       # decide if this is a PO file that should be converted into a translated document,
-       # and perform various sanity checks
+       # decide if this is a PO file that should be converted into a
+       # translated document, and perform various sanity checks
        if (! istranslation($page) || $filtered{$page}{$destpage}) {
                return $content;
        }
@@ -391,6 +390,7 @@ sub otherlanguages ($) { #{{{
 sub pagetemplate (@) { #{{{
        my %params=@_;
         my $page=$params{page};
+        my $destpage=$params{destpage};
         my $template=$params{template};
 
        if (istranslation($page) && $template->query(name => "percenttranslated")) {
@@ -417,6 +417,24 @@ sub pagetemplate (@) { #{{{
                        }
                }
        }
+       # Rely on IkiWiki::Render's genpage() to decide wether
+       # a discussion link should appear on $page; this is not
+       # totally accurate, though: some broken links may be generated
+       # when cgiurl is disabled.
+       # This compromise avoids some code duplication, and will probably
+       # prevent future breakage when ikiwiki internals change.
+       # Known limitations are preferred to future random bugs.
+       if ($template->param('discussionlink') && istranslation($page)) {
+               my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/);
+               $template->param('discussionlink' => htmllink(
+                                                       $page,
+                                                       $destpage,
+                                                       $masterpage . '/' . gettext("Discussion"),
+                                                       noimageinline => 1,
+                                                       forcesubpage => 0,
+                                                       linktext => gettext("Discussion"),
+                                                       ));
+       }
 } # }}}
 
 sub istranslatable ($) { #{{{