aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ManaTools
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2016-01-02 22:54:36 +0100
committerAngelo Naselli <anaselli@linux.it>2016-01-02 22:54:36 +0100
commit206262169aff926837aa8dfaad2bcc94101e664c (patch)
treec2a1a9d8561938fb0edca90b2ca1e5e641cd3c62 /lib/ManaTools
parent470ad65745ae6ca58c7620dfa56e5a4b7167b9cd (diff)
downloadmanatools-206262169aff926837aa8dfaad2bcc94101e664c.tar
manatools-206262169aff926837aa8dfaad2bcc94101e664c.tar.gz
manatools-206262169aff926837aa8dfaad2bcc94101e664c.tar.bz2
manatools-206262169aff926837aa8dfaad2bcc94101e664c.tar.xz
manatools-206262169aff926837aa8dfaad2bcc94101e664c.zip
Read categories and modules using new structure
Diffstat (limited to 'lib/ManaTools')
-rw-r--r--lib/ManaTools/MainDisplay.pm53
1 files changed, 39 insertions, 14 deletions
diff --git a/lib/ManaTools/MainDisplay.pm b/lib/ManaTools/MainDisplay.pm
index 9437ef0b..a3340c03 100644
--- a/lib/ManaTools/MainDisplay.pm
+++ b/lib/ManaTools/MainDisplay.pm
@@ -586,6 +586,23 @@ sub _categorySelected {
return 0;
}
+# 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});
+
+ my @lang = I18N::LangTags::Detect::detect();
+ # Adding default value as English (en)
+ push @lang, 'en';
+ foreach my $l ( @lang ) {
+ return $hash->{$key}->{$l} if $hash->{$key}->{$l};
+ }
+
+ return;
+}
+
## mpan settings
sub _loadSettings {
my ($self, $force_load) = @_;
@@ -612,14 +629,11 @@ sub _loadSettings {
# localized strings
if ($key eq "title" or $key eq "category_title") {
# default is en
- $settings->{$key} = $read->{$key}->{en};
- foreach my $l ( @lang ) {
- if ($read->{$key}->{$l}) {
- $settings->{$key} = $read->{$key}->{$l};
- last;
- }
- }
- $self->logger()->I($self->loc()->N("%s content is <<%s>>", $key, $settings->{$key}));
+ $settings->{$key} = $self->_localizedValue(
+ $read,
+ $key
+ );
+ $self->logger()->I($self->loc()->N("Load settings: %s content is <<%s>>", $key, $settings->{$key}));
}
else {
$settings->{$key} = $read->{$key};
@@ -778,10 +792,15 @@ sub _loadCategories {
my $hasNextCat = $inFile->hasNextCat();
while( $hasNextCat ) {
$tmp = $inFile->getNextCat();
- $tmpCat = $self->_getCategory($tmp->{title});
+ my $title = $self->_localizedValue(
+ $tmp,
+ 'title'
+ );
+ $self->logger()->D($self->loc()->N("Load categories: title content is <<%s>>", $title));
+ $tmpCat = $self->_getCategory($title);
if (!$tmpCat) {
$tmpCat = new ManaTools::Category({
- name => $tmp->{title},
+ name => $title,
icon => $tmp->{icon}
});
}
@@ -796,10 +815,16 @@ sub _loadCategories {
my $loaded = 0;
if (exists $tmp->{title}) {
- if (not $currCategory->moduleLoaded($tmp->{title})) {
- $tmpMod = ManaTools::Module->create(name => $tmp->{title},
- icon => $tmp->{icon},
- launch => $tmp->{launcher}
+ my $title = $self->_localizedValue(
+ $tmp,
+ 'title'
+ );
+ $self->logger()->D($self->loc()->N("Load categories: module title is <<%s>>", $title));
+ if (not $currCategory->moduleLoaded($title)) {
+ $tmpMod = ManaTools::Module->create(
+ name => $title,
+ icon => $tmp->{icon},
+ launch => $tmp->{launcher}
);
}
}