]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/po.pm
avoid hitting the shell with system()
[ikiwiki.git] / IkiWiki / Plugin / po.pm
index 0902322e31be9fbe5d41dba47fe75e3384f37e48..b8c218c5a98c65db81c14726e5cf26986565dcdc 100644 (file)
@@ -47,7 +47,7 @@ sub getsetup () { #{{{
        return
                plugin => {
                        safe => 0,
-                       rebuild => 1, # format plugin
+                       rebuild => 1, # format plugin & changes html filenames
                },
                po_master_language => {
                        type => "string",
@@ -134,6 +134,7 @@ sub refreshpot ($) { #{{{
        # compulsory since this module prevents us from using the porefs option.
        my %po_options = ('porefs' => 'none');
        $doc->{TT}{po_out}=Locale::Po4a::Po->new(\%po_options);
+       $doc->{TT}{po_out}->set_charset('utf-8');
        # do the actual work
        $doc->parse;
        $doc->writepo($potfile);
@@ -148,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 {
@@ -203,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);
                }
@@ -390,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")) {
@@ -416,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 ($) { #{{{