X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/3d8d47d7858ae0e043a28f348fe8aec444d0d35a..f0abaa9fc99463e403fa3b700bd005bcfaa75c6d:/IkiWiki/Plugin/po.pm diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 7deddf9ab..96ba467c5 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -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,15 +362,20 @@ 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(); } } #}}} +# As we're previewing or saving a page, the content may have +# changed, so tell the next filter() invocation it must not be lazy. sub editcontent () { #{{{ my %params=@_; - # as we're previewing or saving a page, the content may have - # changed, so tell the next filter() invocation it must not be lazy + unsetalreadyfiltered($params{page}, $params{page}); return $params{content}; } #}}} @@ -377,22 +385,19 @@ sub editcontent () { #{{{ # | Injected functions # `---- +# Implement po_link_to=current sub mybestlink ($$) { #{{{ my $page=shift; my $link=shift; my $res=$origsubs{'bestlink'}->($page, $link); - if (length $res) { - if ($config{po_link_to} eq "current" - && istranslatable($res) - && istranslation($page)) { - return $res . "." . lang($page); - } - else { - return $res; - } + if (length $res + && $config{po_link_to} eq "current" + && istranslatable($res) + && istranslation($page)) { + return $res . "." . lang($page); } - return ""; + return $res; } #}}} sub mybeautify_urlpath ($) { #{{{ @@ -401,6 +406,7 @@ 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$!/!; } return $res; } #}}} @@ -409,7 +415,7 @@ sub mytargetpage ($$) { #{{{ my $page=shift; my $ext=shift; - if (istranslation($page)) { + if (istranslation($page) || istranslatable($page)) { my ($masterpage, $lang) = (masterpage($page), lang($page)); if (! $config{usedirs} || $masterpage eq 'index') { return $masterpage . "." . $lang . "." . $ext; @@ -418,14 +424,6 @@ sub mytargetpage ($$) { #{{{ return $masterpage . "/index." . $lang . "." . $ext; } } - elsif (istranslatable($page)) { - if (! $config{usedirs} || $page eq 'index') { - return $page . "." . $config{po_master_language}{code} . "." . $ext; - } - else { - return $page . "/index." . $config{po_master_language}{code} . "." . $ext; - } - } return $origsubs{'targetpage'}->($page, $ext); } #}}} @@ -437,7 +435,6 @@ sub myurlto ($$;$) { #{{{ # workaround hard-coded /index.$config{htmlext} in IkiWiki::urlto() if (! length $to && $config{po_link_to} eq "current" - && istranslation($from) && istranslatable('index')) { return IkiWiki::beautify_urlpath(IkiWiki::baseurl($from) . "index." . lang($from) . ".$config{htmlext}"); } @@ -491,11 +488,9 @@ sub istranslatable ($) { #{{{ my $file=$pagesources{$page}; - if (! defined $file - || (defined pagetype($file) && pagetype($file) eq 'po') - || $file =~ /\.pot$/) { - return 0; - } + return 0 unless defined $file; + return 0 if (defined pagetype($file) && pagetype($file) eq 'po'); + return 0 if $file =~ /\.pot$/; return pagespec_match($page, $config{po_translatable_pages}); } #}}} @@ -503,24 +498,17 @@ sub _istranslation ($) { #{{{ my $page=shift; my $file=$pagesources{$page}; - if (! defined $file) { - return IkiWiki::FailReason->new("no file specified"); - } - if (! defined $file - || ! defined pagetype($file) - || ! pagetype($file) eq 'po' - || $file =~ /\.pot$/) { - return 0; - } + return 0 unless (defined $file + && defined pagetype($file) + && pagetype($file) eq 'po'); + return 0 if $file =~ /\.pot$/; my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/); - if (! defined $masterpage || ! defined $lang - || ! (length($masterpage) > 0) || ! (length($lang) > 0) - || ! defined $pagesources{$masterpage} - || ! defined $config{po_slave_languages}{$lang}) { - return 0; - } + return 0 unless (defined $masterpage && defined $lang + && length $masterpage && length $lang + && defined $pagesources{$masterpage} + && defined $config{po_slave_languages}{$lang}); return ($masterpage, $lang) if istranslatable($masterpage); } #}}} @@ -555,6 +543,7 @@ sub lang ($) { #{{{ sub islanguagecode ($) { #{{{ my $code=shift; + return ($code =~ /^[a-z]{2}$/); } #}}} @@ -595,6 +584,7 @@ sub pofile ($$) { #{{{ sub pofiles ($) { #{{{ my $masterfile=shift; + return map pofile($masterfile, $_), (keys %{$config{po_slave_languages}}); } #}}} @@ -723,6 +713,11 @@ sub otherlanguagesloop ($) { #{{{ } @ret; } #}}} +sub homepageurl (;$) { #{{{ + my $page=shift; + + return urlto('', $page); +} #}}} # ,---- # | PageSpec's