]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/po.pm
po: compute internal links from a slave page relative to its master page
[git.ikiwiki.info.git] / IkiWiki / Plugin / po.pm
index 42a125808addaa570f4157d2dfa2c089a7ecbfff..45ed96c65890020295b712697d63b738f8065a86 100644 (file)
@@ -285,6 +285,9 @@ sub pagetemplate (@) { #{{{
        if ($template->query(name => "istranslatable")) {
                $template->param(istranslatable => istranslatable($page));
        }
+       if ($template->query(name => "HOMEPAGEURL")) {
+               $template->param(homepageurl => homepageurl($page));
+       }
        if ($template->query(name => "otherlanguages")) {
                $template->param(otherlanguages => [otherlanguagesloop($page)]);
                map add_depends($page, $_), (values %{otherlanguages($page)});
@@ -359,6 +362,10 @@ sub change(@) { #{{{
                resettranslationscache();
                # Trigger a wiki refresh.
                require IkiWiki::Render;
+               # without preliminary saveindex/loadindex, refresh()
+               # complains about a lot of uninitialized variables
+               IkiWiki::saveindex();
+               IkiWiki::loadindex();
                IkiWiki::refresh();
                IkiWiki::saveindex();
        }
@@ -378,14 +385,14 @@ sub editcontent () { #{{{
 # | Injected functions
 # `----
 
-# Implement po_link_to=current
+# Implement po_link_to 'current' and 'negotiated' settings.
 sub mybestlink ($$) { #{{{
        my $page=shift;
        my $link=shift;
 
-       my $res=$origsubs{'bestlink'}->($page, $link);
+       my $res=$origsubs{'bestlink'}->(masterpage($page), $link);
        if (length $res
-           && $config{po_link_to} eq "current"
+           && ($config{po_link_to} eq "current" || $config{po_link_to} eq "negotiated")
            && istranslatable($res)
            && istranslation($page)) {
                return $res . "." . lang($page);
@@ -399,6 +406,10 @@ sub mybeautify_urlpath ($) { #{{{
        my $res=$origsubs{'beautify_urlpath'}->($url);
        if ($config{po_link_to} eq "negotiated") {
                $res =~ s!/\Qindex.$config{po_master_language}{code}.$config{htmlext}\E$!/!;
+               $res =~ s!/\Qindex.$config{htmlext}\E$!/!;
+               map {
+                       $res =~ s!/\Qindex.$_.$config{htmlext}\E$!/!;
+               } (keys %{$config{po_slave_languages}});
        }
        return $res;
 } #}}}
@@ -490,7 +501,6 @@ sub _istranslation ($) { #{{{
        my $page=shift;
 
        my $file=$pagesources{$page};
-
        return 0 unless (defined $file
                         && defined pagetype($file)
                         && pagetype($file) eq 'po');
@@ -544,7 +554,7 @@ sub otherlanguages($) { #{{{
 
        my %ret;
        if (istranslatable($page)) {
-               %ret = %{$translations{$page}};
+               %ret = %{$translations{$page}} if defined $translations{$page};
        }
        elsif (istranslation($page)) {
                my $masterpage = masterpage($page);
@@ -691,7 +701,7 @@ sub otherlanguagesloop ($) { #{{{
                }
                else {
                        push @ret, {
-                               url => urlto($otherpage, $page),
+                               url => urlto_with_orig_beautiful_urlpath($otherpage, $page),
                                code => $lang,
                                language => languagename($lang),
                                percent => percenttranslated($otherpage),
@@ -705,6 +715,11 @@ sub otherlanguagesloop ($) { #{{{
                } @ret;
 } #}}}
 
+sub homepageurl (;$) { #{{{
+       my $page=shift;
+
+       return urlto('', $page);
+} #}}}
 
 # ,----
 # | PageSpec's