aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2011-05-25 18:01:40 +0200
committerintrigeri <intrigeri@boum.org>2011-05-26 09:39:50 +0200
commit3cd0c1f91a8e4b7accfe75d132066b79da4379fd (patch)
tree07a01329a6bf4c237077401599209130a89f5032
parenta9a5c6eeb82bd50211752e6d3b68924d0dcd6723 (diff)
downloadikiwiki-3cd0c1f91a8e4b7accfe75d132066b79da4379fd.tar
ikiwiki-3cd0c1f91a8e4b7accfe75d132066b79da4379fd.tar.gz
po: support language codes in the form of 'es_AR', and 'arn'.
... additionally to the previously supported two-letters codes.
-rw-r--r--IkiWiki/Plugin/po.pm7
-rwxr-xr-xt/po.t9
2 files changed, 12 insertions, 4 deletions
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index 9ccc79268..d3a996a21 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");
@@ -811,7 +812,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 +854,7 @@ sub lang ($) {
sub islanguagecode ($) {
my $code=shift;
- return $code =~ /^[a-z]{2}$/;
+ return $code =~ /^$language_code_pattern$/;
}
sub otherlanguage_page ($$) {
@@ -1259,7 +1260,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
diff --git a/t/po.t b/t/po.t
index da0bd68a7..5e251fce4 100755
--- a/t/po.t
+++ b/t/po.t
@@ -17,7 +17,7 @@ BEGIN {
}
}
-use Test::More tests => 109;
+use Test::More tests => 114;
BEGIN { use_ok("IkiWiki"); }
@@ -241,3 +241,10 @@ ok(! IkiWiki::Plugin::po::istranslatedto('nontranslatable', 'es'));
ok(! IkiWiki::Plugin::po::istranslatedto('nontranslatable', 'cz'));
ok(! IkiWiki::Plugin::po::istranslatedto('test1.es', 'fr'));
ok(! IkiWiki::Plugin::po::istranslatedto('test1.fr', 'es'));
+
+### islanguagecode
+ok(IkiWiki::Plugin::po::islanguagecode('en'));
+ok(IkiWiki::Plugin::po::islanguagecode('es'));
+ok(IkiWiki::Plugin::po::islanguagecode('arn'));
+ok(! IkiWiki::Plugin::po::islanguagecode('es_'));
+ok(! IkiWiki::Plugin::po::islanguagecode('_en'));