diff options
author | intrigeri <intrigeri@boum.org> | 2008-11-12 17:27:53 +0100 |
---|---|---|
committer | intrigeri <intrigeri@boum.org> | 2008-11-12 17:29:12 +0100 |
commit | aed42eb34ac50912a995dee41ce7dd6e3c3b7f81 (patch) | |
tree | 71a6ed589ae6fe6c90c622f2d156ed8f4271e228 | |
parent | f4815e3b120f130ee0b88e3f301664f08df215a5 (diff) |
po: fix istranslation/istranslatable for pages starting with /
Signed-off-by: intrigeri <intrigeri@boum.org>
-rw-r--r-- | IkiWiki/Plugin/po.pm | 19 | ||||
-rwxr-xr-x | t/po.t | 8 |
2 files changed, 21 insertions, 6 deletions
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 03ee9c33c..402e960a3 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -391,11 +391,9 @@ sub mybestlink ($$) { #{{{ my $link=shift; my $res=$origsubs{'bestlink'}->(masterpage($page), $link); - my $normres=$res; - $normres=~s#^/##; if (length $res && ($config{po_link_to} eq "current" || $config{po_link_to} eq "negotiated") - && istranslatable($normres) + && istranslatable($res) && istranslation($page)) { return $res . "." . lang($page); } @@ -488,9 +486,18 @@ sub myurlto ($$;$) { #{{{ # | Helper functions # `---- +sub maybe_add_leading_slash ($;$) { #{{{ + my $str=shift; + my $add=shift; + $add=1 unless defined $add; + return '/' . $str if $add; + return $str; +} #}}} + sub istranslatable ($) { #{{{ my $page=shift; + $page=~s#^/##; my $file=$pagesources{$page}; return 0 unless defined $file; @@ -502,6 +509,7 @@ sub istranslatable ($) { #{{{ sub _istranslation ($) { #{{{ my $page=shift; + my $hasleadingslash = ($page=~s#^/##); my $file=$pagesources{$page}; return 0 unless (defined $file && defined pagetype($file) @@ -514,15 +522,16 @@ sub _istranslation ($) { #{{{ && defined $pagesources{$masterpage} && defined $config{po_slave_languages}{$lang}); - return ($masterpage, $lang) if istranslatable($masterpage); + return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang); } #}}} sub istranslation ($) { #{{{ my $page=shift; if (1 < (my ($masterpage, $lang) = _istranslation($page))) { + my $hasleadingslash = ($masterpage=~s#^/##); $translations{$masterpage}{$lang}=$page unless exists $translations{$masterpage}{$lang}; - return ($masterpage, $lang); + return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang); } return; } #}}} @@ -17,7 +17,7 @@ BEGIN { } } -use Test::More tests => 59; +use Test::More tests => 65; BEGIN { use_ok("IkiWiki"); } @@ -69,16 +69,22 @@ foreach my $page (keys %pagesources) { # succeed once every two tries... ok(IkiWiki::Plugin::po::istranslatable('index'), "index is translatable"); ok(IkiWiki::Plugin::po::istranslatable('index'), "index is translatable"); +ok(IkiWiki::Plugin::po::istranslatable('/index'), "/index is translatable"); +ok(IkiWiki::Plugin::po::istranslatable('/index'), "/index is translatable"); ok(! IkiWiki::Plugin::po::istranslatable('index.fr'), "index.fr is not translatable"); ok(! IkiWiki::Plugin::po::istranslatable('index.fr'), "index.fr is not translatable"); ok(! IkiWiki::Plugin::po::istranslatable('index.es'), "index.es is not translatable"); ok(! IkiWiki::Plugin::po::istranslatable('index.es'), "index.es is not translatable"); +ok(! IkiWiki::Plugin::po::istranslatable('/index.fr'), "/index.fr is not translatable"); +ok(! IkiWiki::Plugin::po::istranslatable('/index.fr'), "/index.fr is not translatable"); ok(! IkiWiki::Plugin::po::istranslation('index'), "index is not a translation"); ok(! IkiWiki::Plugin::po::istranslation('index'), "index is not a translation"); ok(IkiWiki::Plugin::po::istranslation('index.fr'), "index.fr is a translation"); ok(IkiWiki::Plugin::po::istranslation('index.fr'), "index.fr is a translation"); ok(IkiWiki::Plugin::po::istranslation('index.es'), "index.es is a translation"); ok(IkiWiki::Plugin::po::istranslation('index.es'), "index.es is a translation"); +ok(IkiWiki::Plugin::po::istranslation('/index.fr'), "/index.fr is a translation"); +ok(IkiWiki::Plugin::po::istranslation('/index.fr'), "/index.fr is a translation"); ok(IkiWiki::Plugin::po::istranslatable('test2'), "test2 is translatable"); ok(IkiWiki::Plugin::po::istranslatable('test2'), "test2 is translatable"); ok(! IkiWiki::Plugin::po::istranslation('test2'), "test2 is not a translation"); |