X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/726e0de7d7a9044c8202f777cf2d70af2ed3abce..45d9548940cb9e30a5c453cb367e22bddaf26041:/IkiWiki/Plugin/po.pm diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index 4f8d5036e..6410a1c66 100644 --- a/IkiWiki/Plugin/po.pm +++ b/IkiWiki/Plugin/po.pm @@ -31,6 +31,7 @@ my @origneedsbuild; my %origsubs; my @slavelanguages; # language codes ordered as in config po_slave_languages my %slavelanguages; # language code to name lookup +my $language_code_pattern = '[a-zA-Z]+(?:_[a-zA-Z]+)?'; memoize("istranslatable"); memoize("_istranslation"); @@ -66,8 +67,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); } @@ -339,6 +343,13 @@ sub pagetemplate (@) { if ($template->query(name => "istranslatable")) { $template->param(istranslatable => istranslatable($page)); } + my $lang_code = istranslation($page) ? lang($page) : $master_language_code; + if ($template->query(name => "lang_code")) { + $template->param(lang_code => $lang_code); + } + if ($template->query(name => "lang_name")) { + $template->param(lang_name => languagename($lang_code)); + } if ($template->query(name => "HOMEPAGEURL")) { $template->param(homepageurl => homepageurl($page)); } @@ -621,20 +632,24 @@ 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 ($;$$) { @@ -804,7 +819,7 @@ sub _istranslation ($) { && pagetype($file) eq 'po'; return 0 if $file =~ /\.pot$/; - my ($masterpage, $lang) = ($page =~ /(.*)[.]([a-z]{2})$/); + my ($masterpage, $lang) = ($page =~ /(.*)[.]($language_code_pattern)$/); return 0 unless defined $masterpage && defined $lang && length $masterpage && length $lang && defined $pagesources{$masterpage} @@ -846,7 +861,7 @@ sub lang ($) { sub islanguagecode ($) { my $code=shift; - return $code =~ /^[a-z]{2}$/; + return $code =~ /^$language_code_pattern$/; } sub otherlanguage_page ($$) { @@ -1238,6 +1253,7 @@ sub po4a_options($) { # how to disable options is not consistent across po4a modules $options{includessi} = ''; $options{includeexternal} = 0; + $options{ontagerror} = 'warn'; } elsif ($pagetype eq 'mdwn') { $options{markdown} = 1; @@ -1252,7 +1268,7 @@ sub po4a_options($) { sub splitlangpair ($) { my $pair=shift; - my ($code, $name) = ( $pair =~ /^([a-z]{2})\|(.+)$/ ); + my ($code, $name) = ( $pair =~ /^($language_code_pattern)\|(.+)$/ ); if (! defined $code || ! defined $name || ! length $code || ! length $name) { # not a fatal error to avoid breaking if used with web setup