Permalink
Browse files

Item14477: better handling of enabled languages

1 parent 6d03605 commit d152a7516fda3f95192e233406fd3f2a140686cf MichaelDaum committed Sep 13, 2017
@@ -1,4 +1,4 @@
-%META:TOPICINFO{author="ProjectContributor" comment="" date="1464687321" format="1.1" version="1"}%
+%META:TOPICINFO{author="ProjectContributor" comment="" date="1500461121" format="1.1" version="1"}%
%META:TOPICPARENT{name="MultiLingualPlugin"}%
---+!! %TOPIC%
@@ -1,4 +1,4 @@
-%META:TOPICINFO{author="ProjectContributor" comment="" date="1464687321" format="1.1" version="1"}%
+%META:TOPICINFO{author="ProjectContributor" comment="" date="1500461121" format="1.1" version="1"}%
---+!! %TOPIC%
%FORMFIELD{"Description"}%
@@ -168,7 +168,6 @@ This is recommended for any new Foswiki installation. See Foswiki:Extensions/Cha
Render a full table of all known languages:
%LANGUAGES{
- "bg, zh-cn, zh-tw, cs, da, nl, en, fi, fr, de, it, ja, ko, no, pl, pt, pt-br, ru, es, sv, tr, uk"
header="| *#* | *Language* | *Name* | *Code* | *Country* | *Flag* |$n"
format="| $index | $language | $name | $code | $country | $icon(32) |"
separator="$n"
@@ -204,6 +203,7 @@ in his/her browser or the value of ={DefaultLanguage}= as configured to this plu
%$DEPENDENCIES%
---++ Change History
+| 13 Sep 2017 | better handling of enabled languages; added Greek flag to mapping; suppress Locale::Codes' error reporting to stderr |
| 16 Jan 2017 | fixed crash translating strings with certain bracket links |
| 02 Sep 2016 | added support for <nop>WebLexicon |
| 31 May 2016 | added =arg&lt;N>= way of specifying arguments to =%TRANSLATE= |
@@ -21,8 +21,8 @@ use warnings;
use Foswiki::Func ();
use Foswiki::Plugins ();
-our $VERSION = '3.01';
-our $RELEASE = '16 Jan 2017';
+our $VERSION = '3.10';
+our $RELEASE = '13 Sep 2017';
our $SHORTDESCRIPTION = 'Support for a multi lingual Foswiki';
our $NO_PREFS_IN_TOPIC = 1;
our $core;
@@ -262,7 +262,8 @@ sub LANGUAGES {
my $include = $params->{include};
my $exclude = $params->{exclude};
- my $enabledLanguages = $this->{session}->i18n->enabled_languages();
+ my $enabledLanguages = $this->enabledLanguages();
+ #print STDERR "enabled_languages=".join(", ", keys %$enabledLanguages)."\n";
my @records = ();
if (defined $languages) {
@@ -332,6 +333,33 @@ sub LANGUAGES {
return $result;
}
+sub enabledLanguages {
+ my ($this) = @_;
+
+ unless (defined $this->{enabledLanguages}) {
+
+ # temporarily disable error messages in stderr
+ $Locale::Country::obj->show_errors(0) if defined $Locale::Country::obj;
+
+ my $enabledLanguages = $this->{session}->i18n->enabled_languages();
+ $this->{enabledLanguages} = {};
+
+ # weed out those not known to Locale::Codes
+ foreach my $code (keys %{$enabledLanguages}) {
+ if (getLanguageOfCode($code)) {
+ $this->{enabledLanguages}{$code} = $enabledLanguages->{$code};
+ } else {
+ #print STDERR "WARNING: $code unkown to Locale::Country\n";
+ }
+ }
+
+ # enable it again
+ $Locale::Country::obj->show_errors(1) if defined $Locale::Country::obj;
+ }
+
+ return $this->{enabledLanguages};
+}
+
sub getFlagImage {
my ($this, $code, $size) = @_;
@@ -379,7 +407,7 @@ sub getCountryOfCode {
$code = $1;
}
- return code2country($code, LOCALE_CODE_ALPHA_2) || '';
+ return code2country($code, LOCALE_CODE_ALPHA_2, 1) || '';
}
sub getLanguageOfCode {
@@ -389,7 +417,9 @@ sub getLanguageOfCode {
$code = $1;
}
- return code2language($code, LOCALE_CODE_ALPHA_2) || '';
+ my $lang = code2language($code, LOCALE_CODE_ALPHA_2, 1) || '';
+ $lang =~ s/\(\d+\-\)//; # weed out Modern Greek (1453-)
+ return $lang;
}
sub getLabelOfCode {
@@ -398,7 +428,7 @@ sub getLabelOfCode {
my $label;
if ($code =~ /^(\w+)-(\w+)$/) {
$code = $1;
- my ($lname, $cname) = ((code2language($1, LOCALE_CODE_ALPHA_2) || ''), (code2country($2, LOCALE_CODE_ALPHA_2) || ''));
+ my ($lname, $cname) = ((code2language($1, LOCALE_CODE_ALPHA_2, 1) || ''), (code2country($2, LOCALE_CODE_ALPHA_2, 1) || ''));
if ($lname && $cname) {
$label = "$lname ($cname)";
} elsif ($lname) {
@@ -409,7 +439,8 @@ sub getLabelOfCode {
$label = "$code";
}
} else {
- $label = code2language($code, LOCALE_CODE_ALPHA_2) || "$code";
+ $label = code2language($code, LOCALE_CODE_ALPHA_2, 1) || "$code";
+ $label =~ s/\(\d+\-\)//; # weed out Modern Greek (1453-)
}
return $label;
@@ -1,3 +1,4 @@
+!noci
data/System/LexiconForm.txt 0644
data/System/MultiLingualPlugin.txt 0644
lib/Foswiki/Plugins/MultiLingualPlugin/Config.spec 0644
@@ -6,6 +6,7 @@ cs = Czech-Republic.png
da = Denmark.png
de = Germany.png
es = Spain.png
+el = Greece.png
fi = Finland.png
fr = France.png
gb = United-Kingdom-Great-Britain.png

0 comments on commit d152a75

Please sign in to comment.