po: change a bit the way links are generated
authorintrigeri <intrigeri@boum.org>
Tue, 11 Nov 2008 21:26:01 +0000 (22:26 +0100)
committerintrigeri <intrigeri@boum.org>
Tue, 11 Nov 2008 21:29:47 +0000 (22:29 +0100)
This will soon enable usage of translated page titles in link.

Signed-off-by: intrigeri <intrigeri@boum.org>
IkiWiki/Plugin/po.pm
t/po.t

index 96ba467c58d63f4c2ec07a78d281c8d60759d3ef..d5964ea81136f54f33739a8183fcc8d312404313 100644 (file)
@@ -385,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);
        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);
@@ -407,6 +407,9 @@ sub mybeautify_urlpath ($) { #{{{
        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;
 } #}}}
@@ -699,7 +702,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),
diff --git a/t/po.t b/t/po.t
index 02115e16f4a5399af6476238bdadabd33a59f4e4..79e087318ed6d2dbc7069ef2a690cf375a2ab26a 100755 (executable)
--- a/t/po.t
+++ b/t/po.t
@@ -17,7 +17,7 @@ BEGIN {
        }
 }
 
-use Test::More tests => 58;
+use Test::More tests => 59;
 
 BEGIN { use_ok("IkiWiki"); }
 
@@ -163,7 +163,7 @@ is(bestlink('test1.fr', 'test2'), 'test2.fr', "$msgprefix test1.fr -> test2");
 is(bestlink('test1.fr', 'test2.es'), 'test2.es', "$msgprefix test1.fr -> test2.es");
 $config{po_link_to}='negotiated';
 $msgprefix="bestlink (po_link_to=negotiated)";
-is(bestlink('test1.fr', 'test2'), 'test2', "$msgprefix test1.fr -> test2");
+is(bestlink('test1.fr', 'test2'), 'test2.fr', "$msgprefix test1.fr -> test2");
 is(bestlink('test1.fr', 'test2.es'), 'test2.es', "$msgprefix test1.fr -> test2.es");
 
 ### beautify_urlpath
@@ -173,5 +173,6 @@ is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/index.en.html', "$
 is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html");
 $config{po_link_to}='negotiated';
 $msgprefix="beautify_urlpath (po_link_to=negotiated)";
+is(IkiWiki::beautify_urlpath('test1/index.html'), './test1/', "$msgprefix test1/index.html");
 is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/', "$msgprefix test1/index.en.html");
-is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html");
+is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/', "$msgprefix test1/index.fr.html");