X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/5edddf87caf566546c8d8e29c45950ee9408dc0c..d57c45b2d41b760082d86e4de1c5893ffd60b6e5:/IkiWiki/Plugin/po.pm?ds=sidebyside diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index a233fb5af..9ccc79268 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -30,6 +30,7 @@ my %translations; my @origneedsbuild; my %origsubs; my @slavelanguages; # language codes ordered as in config po_slave_languages +my %slavelanguages; # language code to name lookup memoize("istranslatable"); memoize("_istranslation"); @@ -37,7 +38,8 @@ memoize("percenttranslated"); sub import { hook(type => "getsetup", id => "po", call => \&getsetup); - hook(type => "checkconfig", id => "po", call => \&checkconfig); + hook(type => "checkconfig", id => "po", call => \&checkconfig, + last => 1); hook(type => "needsbuild", id => "po", call => \&needsbuild); hook(type => "scan", id => "po", call => \&scan, last => 1); hook(type => "filter", id => "po", call => \&filter); @@ -64,8 +66,11 @@ sub import { inject(name => "IkiWiki::urlto", call => \&myurlto); $origsubs{'cgiurl'}=\&IkiWiki::cgiurl; inject(name => "IkiWiki::cgiurl", call => \&mycgiurl); - $origsubs{'rootpage'}=\&IkiWiki::rootpage; - inject(name => "IkiWiki::rootpage", call => \&myrootpage); + if (IkiWiki->can('rootpage')) { + $origsubs{'rootpage'}=\&IkiWiki::rootpage; + inject(name => "IkiWiki::rootpage", call => \&myrootpage) + if defined $origsubs{'rootpage'}; + } $origsubs{'isselflink'}=\&IkiWiki::isselflink; inject(name => "IkiWiki::isselflink", call => \&myisselflink); } @@ -138,6 +143,7 @@ sub checkconfig () { else { $master_language_code=$config{po_master_language}{code}; $master_language_name=$config{po_master_language}{name}; + $config{po_master_language}=joinlangpair($master_language_code, $master_language_name); } } if (! defined $master_language_code) { @@ -148,23 +154,25 @@ sub checkconfig () { } if (ref $config{po_slave_languages} eq 'ARRAY') { - my %slaves; foreach my $pair (@{$config{po_slave_languages}}) { my ($code, $name)=splitlangpair($pair); - if (defined $code) { + if (defined $code && ! exists $slavelanguages{$code}) { push @slavelanguages, $code; - $slaves{$code} = $name; + $slavelanguages{$code} = $name; } } - $config{po_slave_languages} = \%slaves; } elsif (ref $config{po_slave_languages} eq 'HASH') { + %slavelanguages=%{$config{po_slave_languages}}; @slavelanguages = sort { $config{po_slave_languages}->{$a} cmp $config{po_slave_languages}->{$b}; - } keys %{$config{po_slave_languages}}; + } keys %slavelanguages; + $config{po_slave_languages}=[ + map { joinlangpair($_, $slavelanguages{$_}) } @slavelanguages + ] } - delete $config{po_slave_languages}{$master_language_code}; + delete $slavelanguages{$master_language_code}; map { islanguagecode($_) @@ -363,7 +371,8 @@ sub pagetemplate (@) { && $masterpage eq "index") { $template->param('parentlinks' => []); } - if (ishomepage($page) && $template->query(name => "title")) { + if (ishomepage($page) && $template->query(name => "title") + && !$template->param("title_overridden")) { $template->param(title => $config{wikiname}); } } @@ -615,23 +624,27 @@ sub mybeautify_urlpath ($) { return $res; } -sub mytargetpage ($$) { +sub mytargetpage ($$;$) { my $page=shift; my $ext=shift; + my $filename=shift; if (istranslation($page) || istranslatable($page)) { my ($masterpage, $lang) = (masterpage($page), lang($page)); - if (! $config{usedirs} || $masterpage eq 'index') { + if (defined $filename) { + return $masterpage . "/" . $filename . "." . $lang . "." . $ext; + } + elsif (! $config{usedirs} || $masterpage eq 'index') { return $masterpage . "." . $lang . "." . $ext; } else { return $masterpage . "/index." . $lang . "." . $ext; } } - return $origsubs{'targetpage'}->($page, $ext); + return $origsubs{'targetpage'}->($page, $ext, $filename); } -sub myurlto ($$;$) { +sub myurlto ($;$$) { my $to=shift; my $from=shift; my $absolute=shift; @@ -640,7 +653,12 @@ sub myurlto ($$;$) { if (! length $to && $config{po_link_to} eq "current" && istranslatable('index')) { - return IkiWiki::beautify_urlpath(IkiWiki::baseurl($from) . "index." . lang($from) . ".$config{htmlext}"); + if (defined $from) { + return IkiWiki::beautify_urlpath(IkiWiki::baseurl($from) . "index." . lang($from) . ".$config{htmlext}"); + } + else { + return $origsubs{'urlto'}->($to,$from,$absolute); + } } # avoid using our injected beautify_urlpath if run by cgi_editpage, # so that one is redirected to the just-edited page rather than to the @@ -797,7 +815,7 @@ sub _istranslation ($) { return 0 unless defined $masterpage && defined $lang && length $masterpage && length $lang && defined $pagesources{$masterpage} - && defined $config{po_slave_languages}{$lang}; + && defined $slavelanguages{$lang}; return (maybe_add_leading_slash($masterpage, $hasleadingslash), $lang) if istranslatable($masterpage); @@ -1015,8 +1033,8 @@ sub languagename ($) { return $master_language_name if $code eq $master_language_code; - return $config{po_slave_languages}{$code} - if defined $config{po_slave_languages}{$code}; + return $slavelanguages{$code} + if defined $slavelanguages{$code}; return; } @@ -1245,13 +1263,20 @@ sub splitlangpair ($) { if (! defined $code || ! defined $name || ! length $code || ! length $name) { # not a fatal error to avoid breaking if used with web setup - print STDERR sprintf(gettext("%s has invalid syntax: must use CODE|NAME"), - $pair)."\n"; + warn sprintf(gettext("%s has invalid syntax: must use CODE|NAME"), + $pair); } return $code, $name; } +sub joinlangpair ($$) { + my $code=shift; + my $name=shift; + + return "$code|$name"; +} + # ,---- # | PageSpecs # `---- @@ -1286,7 +1311,7 @@ sub match_lang ($$;@) { my $regexp=IkiWiki::glob2re($wanted); my $lang=IkiWiki::Plugin::po::lang($page); - if ($lang !~ /^$regexp$/i) { + if ($lang !~ $regexp) { return IkiWiki::FailReason->new("file language is $lang, not $wanted"); } else {