X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/8084c79f920e5b4cb961dc6df3641a0253384eb5..739554622fa1caa6bcc0474ebbdcd9db3627389d:/IkiWiki/Plugin/po.pm?ds=sidebyside diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm index ec58c515b..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"); @@ -342,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)); } @@ -811,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} @@ -853,7 +861,7 @@ sub lang ($) { sub islanguagecode ($) { my $code=shift; - return $code =~ /^[a-z]{2}$/; + return $code =~ /^$language_code_pattern$/; } sub otherlanguage_page ($$) { @@ -1260,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