X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/f0abaa9fc99463e403fa3b700bd005bcfaa75c6d..e18a9d9a881897cbef82adfd992fe0a38c86d8d4:/IkiWiki/Plugin/po.pm diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 96ba467c5..402e960a3 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -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); + 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); @@ -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; } #}}} @@ -483,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; @@ -497,8 +509,8 @@ sub istranslatable ($) { #{{{ sub _istranslation ($) { #{{{ my $page=shift; + my $hasleadingslash = ($page=~s#^/##); my $file=$pagesources{$page}; - return 0 unless (defined $file && defined pagetype($file) && pagetype($file) eq 'po'); @@ -510,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; } #}}} @@ -552,7 +565,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); @@ -699,7 +712,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),