aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2016-01-06 21:18:37 +0100
committerAngelo Naselli <anaselli@linux.it>2016-01-06 21:20:18 +0100
commite3c1a061532c6dbc4dbae6e4eff5c689035f502c (patch)
tree03d442db78968e2c567b652e01afbe5f63c6bf24 /lib
parent085599b72d6317fe0364caa7ecfc8346e3a6a40a (diff)
downloadmanatools-e3c1a061532c6dbc4dbae6e4eff5c689035f502c.tar
manatools-e3c1a061532c6dbc4dbae6e4eff5c689035f502c.tar.gz
manatools-e3c1a061532c6dbc4dbae6e4eff5c689035f502c.tar.bz2
manatools-e3c1a061532c6dbc4dbae6e4eff5c689035f502c.tar.xz
manatools-e3c1a061532c6dbc4dbae6e4eff5c689035f502c.zip
Now reading localized descriptions
Diffstat (limited to 'lib')
-rw-r--r--lib/ManaTools/Module/Firewall.pm53
1 files changed, 44 insertions, 9 deletions
diff --git a/lib/ManaTools/Module/Firewall.pm b/lib/ManaTools/Module/Firewall.pm
index a5407e59..03f35c0c 100644
--- a/lib/ManaTools/Module/Firewall.pm
+++ b/lib/ManaTools/Module/Firewall.pm
@@ -26,6 +26,7 @@ use Moose;
use Moose::Autobox;
use utf8;
use File::ShareDir ':ALL';
+use I18N::LangTags::Detect;
use yui;
use ManaTools::Shared qw(trim);
@@ -218,6 +219,29 @@ sub _initUnlisted {
return \@unlisted;
}
+
+# return the localized string from a hash and given the key
+# by default en value
+sub _localizedValue {
+ my ($self, $hash, $key) = @_;
+
+ return if !defined($hash->{$key});
+
+ if (ref($hash->{$key}) ne "HASH") {
+ # Force array is set for "title"
+ return $hash->{$key}[0];
+ }
+
+ my @lang = I18N::LangTags::Detect::detect();
+ # Adding default value as English (en)
+ push @lang, 'en';
+ foreach my $l ( @lang ) {
+ return $hash->{$key}->{$l} if defined($hash->{$key}->{$l});
+ }
+
+ return;
+}
+
#=============================================================
sub get_servers {
@@ -225,17 +249,28 @@ sub get_servers {
my $fh = undef;
my @all_servers = ();
my $xml = XML::Simple->new();
- my $data = $xml->XMLin($self->conf());
- foreach my $server (keys %{$data->{server}})
+ my $data = $xml->XMLin($self->conf(),
+ ContentKey => '-content',
+ ForceArray => ['description'],
+ KeyAttr=>{
+ description => "xml:lang",
+ }
+ );
+
+ foreach my $server (@{$data->{server}})
{
+ my $description = $self->_localizedValue(
+ $server,
+ 'description'
+ );
push(@all_servers, {
- id => $server,
- name => $data->{server}->{$server}->{description},
- pkg => $data->{server}->{$server}->{packages},
- ports => $data->{server}->{$server}->{ports},
- hide => (defined($data->{server}->{$server}->{hide}) ? 1 : 0),
- default => (defined($data->{server}->{$server}->{default}) ? 1 : 0),
- pos => (defined($data->{server}->{$server}->{pos}) ? $data->{server}->{$server}->{pos} : 0),
+ id => $server->{id},
+ name => $description,
+ pkg => $server->{packages},
+ ports => $server->{ports},
+ hide => (defined($server->{hide}) ? 1 : 0),
+ default => (defined($server->{default}) ? 1 : 0),
+ pos => (defined($server->{pos}) ? $server->{pos} : 0),
});
}
my @sorted = sort { ${a}->{pos} <=> ${b}->{pos} } @all_servers;