Skip to content

Commit

Permalink
Item14477: better handling of enabled languages
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Sep 13, 2017
1 parent 6d03605 commit d152a75
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion data/System/LexiconForm.txt
@@ -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%

Expand Down
4 changes: 2 additions & 2 deletions data/System/MultiLingualPlugin.txt
@@ -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"}%

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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= |
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/MultiLingualPlugin.pm
Expand Up @@ -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;
Expand Down
41 changes: 36 additions & 5 deletions lib/Foswiki/Plugins/MultiLingualPlugin/Core.pm
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) = @_;

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/MultiLingualPlugin/MANIFEST
@@ -1,3 +1,4 @@
!noci
data/System/LexiconForm.txt 0644
data/System/MultiLingualPlugin.txt 0644
lib/Foswiki/Plugins/MultiLingualPlugin/Config.spec 0644
Expand Down
1 change: 1 addition & 0 deletions pub/System/MultiLingualPlugin/flags/mapping.txt
Expand Up @@ -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
Expand Down

0 comments on commit d152a75

Please sign in to comment.