summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/JWebmail/I18N.pm32
-rw-r--r--lib/JWebmail/I18N/de.pm (renamed from lib/JWebmail/I18N/de_de.pm)93
-rw-r--r--lib/JWebmail/I18N/en.pm18
-rw-r--r--lib/JWebmail/I18N/en_us.pm13
-rw-r--r--lib/JWebmail/Plugin/I18N2.pm50
-rw-r--r--templates/headers/_display_bot_nav.html.ep4
-rw-r--r--templates/headers/_display_folders.html.ep10
-rw-r--r--templates/headers/_display_headers.html.ep4
-rw-r--r--templates/headers/_pagination1.html.ep2
-rw-r--r--templates/webmail/displayheaders.html.ep2
10 files changed, 155 insertions, 73 deletions
diff --git a/lib/JWebmail/I18N.pm b/lib/JWebmail/I18N.pm
index 576c413..190f4be 100644
--- a/lib/JWebmail/I18N.pm
+++ b/lib/JWebmail/I18N.pm
@@ -1,8 +1,40 @@
package JWebmail::I18N;
+use v5.22;
+use warnings;
+use utf8;
+
use parent 'Locale::Maketext';
+sub init {
+ my $self = shift;
+ $self->SUPER::init(@_);
+
+ $self->fail_with('log_on_failure');
+}
+
+sub fallback_languages { return (); }
+
+sub log_on_failure {
+ my $self = shift;
+ my $prase = shift;
+ $self->logger->("missing translation for @{[$self->language_tag]}:'$prase'");
+ $self->failure_handler_auto($prase, @_);
+}
+
+sub logger {
+ my $self = shift;
+ if (@_) {
+ $self->{_jwm_logger} = $_[0];
+ return $self;
+ }
+ else {
+ return $self->{_jwm_logger};
+ }
+}
+
+
1
__END__
diff --git a/lib/JWebmail/I18N/de_de.pm b/lib/JWebmail/I18N/de.pm
index 637e88f..1b364fb 100644
--- a/lib/JWebmail/I18N/de_de.pm
+++ b/lib/JWebmail/I18N/de.pm
@@ -1,4 +1,4 @@
-package JWebmail::I18N::de_de;
+package JWebmail::I18N::de;
use v5.22;
use warnings;
@@ -8,60 +8,85 @@ use parent 'JWebmail::I18N';
our %Lexicon = (
- 'login' => 'anmelden',
- 'userid' => 'nuzerkennung',
- 'password' => 'passwort',
- 'failed' => 'fehlgeschlagen',
+ ## mainlayout
+ 'version' => 'Version',
'about' => 'über',
- 'mbox_size' => 'mailboxgröße',
- # and = und
- 'subject' => 'betreff',
- 'version' => 'version',
+
+ ## writemail
+ # qw(subject send back)
+ 'send to' => 'senden an',
+ 'answer_to' => 'antworten gehen an',
+ 'content' => 'Inhalt',
+ 'attach file' => 'Datei anhängen',
+
+ ## readmail
+ # qw(subject date size)
+ 'content-type' => 'inhaltsart',
+ 'back' => 'zurück',
'from' => 'von',
'to' => 'für',
'cc' => 'cc',
- 'date' => 'datum',
- 'size' => 'größe',
- 'content-type' => 'inhaltsart',
- 'send to' => 'senden an',
- 'answer_to' => 'antworten gehen an',
- 'content' => 'inhalt',
- 'check_all' => 'alle markieren',
- 'move' => 'verschieben',
- 'nr' => 'nummer',
- 'status' => 'mehrteilig',
- 'logout' => 'abmelden',
- 'compose' => 'schreiben',
- 'search' => 'suche',
+ 'bcc' => 'bcc',
+ 'and' => 'und',
+
+ ## _pagination1
+ 'page [_1] of [_2]' => 'Seite [_1] von [_2]',
+
+ ## _pagination2
+ 'page' => 'Seite',
'of' => 'von',
- 'messages' => 'nachrichten',
- 'new' => 'neu',
- 'mbox_size' => 'mailboxgröße',
- 'home' => 'übersicht',
- 'no' => 'nein',
- 'yes' => 'ja',
- 'page' => 'seite',
'next' => 'nächste',
'last' => 'letzte',
'first' => 'erste',
'previous' => 'vorherige',
+
+ ## _display_top_nav
+ 'logout' => 'abmelden',
+ 'search' => 'suche',
+ 'compose' => 'schreiben',
+
+ ## _display_headers
+ 'recipient' => 'empfänger',
+ 'date' => 'datum',
+ 'subject' => 'betreff',
+ 'size' => 'größe',
'sender' => 'gesendet von',
- 'back' => 'zurück',
+ 'status' => 'mehrteilig',
+ # 'no' => 'nein',
+ # 'yes' => 'ja',
- # Mailboxen
+ ## _display_folders
+ '[_1] of [_2] messages' => '[_1] von [_2] Nachrichten',
+ ', [_1] new' => ', [_1] Neue',
+ ' - mailbox size: [_1]', => ' - Mailboxgröße: [_1]',
+ '_mailbox_root' => 'Stammverzeichnis',
+
+ ## _display_folders mailbox names
'queue' => 'warteschlange',
'drafts' => 'vorlagen',
'home' => 'wurzelverzeichnis',
+ 'home' => 'übersicht',
+
+ ## _display_bot_nav
+ 'check all' => 'alle markieren',
+ 'move' => 'verschieben',
+ 'move to' => 'verschieben nach',
+
+ ## displayheaders
+ 'This folder is empty!' => 'Dieses Verzeichnis ist leer!',
- # Fehler
+ ## login
+ 'login' => 'anmelden',
+ 'userid' => 'nuzerkennung',
+ 'password' => 'passwort',
+
+ ## Controller
'No active session.' => 'Keine aktive Sitzung.',
'Login failed!' => 'Einloggen fehlgeschlagen!',
-
'no_folder' => 'Dieses Verzeichnis gibt es nicht.',
'error_send' => 'Die Nachricht konnte nicht gesendet werden.',
'succ_send' => 'Die Nachricht wurde verschikt.',
'succ_move' => 'Nachrichten wurden verschoben.',
- 'empty_folder' => 'Dies Verzeichnis ist leer.',
);
diff --git a/lib/JWebmail/I18N/en.pm b/lib/JWebmail/I18N/en.pm
new file mode 100644
index 0000000..a57d1eb
--- /dev/null
+++ b/lib/JWebmail/I18N/en.pm
@@ -0,0 +1,18 @@
+package JWebmail::I18N::en;
+
+use v5.22;
+use warnings;
+use utf8;
+
+use parent 'JWebmail::I18N';
+
+
+our %Lexicon = (
+ _AUTO => 1,
+
+ # _display_folders
+ '_mailbox_root' => 'Home',
+);
+
+
+1
diff --git a/lib/JWebmail/I18N/en_us.pm b/lib/JWebmail/I18N/en_us.pm
deleted file mode 100644
index 22de05e..0000000
--- a/lib/JWebmail/I18N/en_us.pm
+++ /dev/null
@@ -1,13 +0,0 @@
-package JWebmail::I18N::en_us;
-
-use v5.22;
-use warnings;
-use utf8;
-
-use parent 'JWebmail::I18N';
-
-
-our %Lexicon = (_AUTO => 1);
-
-
-1
diff --git a/lib/JWebmail/Plugin/I18N2.pm b/lib/JWebmail/Plugin/I18N2.pm
index 8c57ec5..31d6234 100644
--- a/lib/JWebmail/Plugin/I18N2.pm
+++ b/lib/JWebmail/Plugin/I18N2.pm
@@ -25,15 +25,17 @@ package JWebmail::Plugin::I18N2::Maketext {
my @res = grep { /\.pm$/ && -f "$lexica/$_" } readdir $dh;
closedir($dh);
@languages = map { scalar fileparse $_, '.pm' } @res;
+ @languages = map { my ($l, $c) = split '_', $_, 2; $c ? "$l-\U$c" : $l } @languages;
}
+ if (my $dl = $conf->{default_language}) { push @languages, $dl; };
my $self = {};
for (@languages) {
$self->{$_} = JWebmail::I18N->get_handle($_) || die "unable to load language $_";
}
- if (my $dl = $conf->{default_language}) {
- $self->{$dl} = JWebmail::I18N->get_handle($dl) || die "unable to load language $dl";
+ if (my $l = $conf->{log}) {
+ $_->logger($l) for values %$self;
}
return bless $self, $class;
@@ -42,7 +44,7 @@ package JWebmail::Plugin::I18N2::Maketext {
sub languages {
my $self = shift;
if (@_) {
- return exists $self->{$_[0]};
+ return exists $self->{$_[0] || ''};
}
return wantarray ? sort keys $self->%* : scalar keys $self->%*;
}
@@ -53,7 +55,6 @@ package JWebmail::Plugin::I18N2::Maketext {
my $phrase = shift;
return $self->{$lang}->maketext($phrase, @_);
}
-
}
package JWebmail::Plugin::I18N2::Translator {
@@ -66,6 +67,10 @@ package JWebmail::Plugin::I18N2::Translator {
my $cls = shift;
my $conf = @_ == 1 ? shift : {@_};
+ my $self = bless {}, $cls;
+
+ $self->_log($conf->{log} || sub { @_ = $_[0]->() if ref $_[0] eq 'CODE'; local $" = ' '; warn "@_" });
+
my @languages = keys %{$conf->{languages} // {}};
unless (@languages) {
@@ -73,20 +78,19 @@ package JWebmail::Plugin::I18N2::Translator {
}
# load languages
- my $self = {};
for my $l (@languages) {
if (my $dict = __loadi18n($conf->{directory}, $l)) {
$self->{$l} = $dict;
}
}
- return bless $self, $cls;
+ return $self;
}
sub languages {
my $self = shift;
if (@_) {
- return exists $self->{$_[0]};
+ return exists $self->{$_[0] || ''};
}
return wantarray ? sort keys $self->%* : scalar keys $self->%*;
}
@@ -95,7 +99,27 @@ package JWebmail::Plugin::I18N2::Translator {
my $self = shift;
my $lang = shift;
my $word = shift;
- return $self->{$lang}{$word};
+
+ my $res = $self->{$lang}{$word};
+ unless ($res) {
+ local $" = ' ';
+ $self->_log->("missing translation for $lang:'$word' @{[ caller(1) ]}[0..2]");
+ }
+ if (@_) {
+ $res = sprintf($res, @_);
+ }
+ return $res;
+ }
+
+ sub _log {
+ my $self = shift;
+ if (@_) {
+ $self->{_log} = $_[0];
+ return $self;
+ }
+ else {
+ return $self->{_log};
+ }
}
sub __loadi18n {
@@ -172,6 +196,7 @@ sub register {
my $t = $translator->(
default_language => $defaultLang,
directory => $fileLocation,
+ log => sub { $i18n_log->warn(@_) },
%{$conf->{rest} // {}}
);
@@ -199,12 +224,7 @@ sub register {
my $word = shift;
my $lang = $c->stash('lang');
- my $res = $t->translate($lang, $word, @_);
- unless ($res) {
- local $" = ' ';
- $app->log->warn('[' . __PACKAGE__ . "] missing translation for $lang:'$word' @{[ caller(1) ]}[0..2]");
- }
- return $res;
+ return $t->translate($lang, $word, @_);
});
# modify incoming and generated urls
@@ -212,7 +232,7 @@ sub register {
my $c = shift;
unshift @{ $c->req->url->path->parts }, ''
- unless $t->languages($c->req->url->path->parts->[0] || '');
+ unless $t->languages($c->req->url->path->parts->[0]);
my $ext_match = $c->match->with_roles('JWebmail::Plugin::I18N2::Match::Role');
$ext_match->_i18n2_stash($c->stash);
diff --git a/templates/headers/_display_bot_nav.html.ep b/templates/headers/_display_bot_nav.html.ep
index 9064d6e..5a58b77 100644
--- a/templates/headers/_display_bot_nav.html.ep
+++ b/templates/headers/_display_bot_nav.html.ep
@@ -5,14 +5,14 @@
</div>
<div class="pure-u-1-2 pure-u-md-1-4">
- <label for=allbox><%= l 'check_all' %></label>
+ <label for=allbox><%= l 'check all' %></label>
<input name=allbox type=checkbox onclick="check_all(this)">
</div>
<div class="pure-u-1-1 pure-u-md-1-2">
%= form_for move => (id => 'move-mail') => (class => 'pure-form') => begin
<fieldset>
- %= label_for 'select-folder' => l('move') . ' ' . l('to')
+ %= label_for 'select-folder' => l('move to')
%= select_field folder => [grep {$_ ne $folder} @$mail_folders] => (id => 'select-folder')
%= csrf_field
%= submit_button l('move') => (class => 'pure-button')
diff --git a/templates/headers/_display_folders.html.ep b/templates/headers/_display_folders.html.ep
index bf8a346..856844d 100644
--- a/templates/headers/_display_folders.html.ep
+++ b/templates/headers/_display_folders.html.ep
@@ -4,14 +4,14 @@
<nav class="pure-menu pure-menu-horizontal">
<strong class="pure-menu-heading">
- %= l($folder) || $folder || 'Root'
+ %= l($folder || '_mailbox_root')
</strong>
<ul class="pure-menu-list">
% for my $v (grep {$_ ne $folder} @$mail_folders) {
<li class="pure-menu-item">
%= link_to '' => {folder => $v} => (class => 'bright') => begin
- %= $v ? (l($v) || $v) : l 'Home'
+ %= l($v || '_mailbox_root')
% end
</li>
% }
@@ -21,9 +21,9 @@
</div>
<p class="pure-u-1-1 pure-u-md-1-2">
- <%= "$first_item - $last_item " . l('of') . " $total_items " . l('messages') %>\
- <%= ", $total_new_mails " . l('new') if $total_new_mails > 0 =%>
- <%= ' - ' . ucfirst(l 'mbox_size') . ": " . print_sizes10 $total_size if $total_size %>
+ <%= l('[_1] of [_2] messages', $last_item - $first_item + 1, $total_items) %>\
+ <%= l(', [_1] new', $total_new_mails) if $total_new_mails > 0 =%>
+ <%= l(' - mailbox size: [_1]', print_sizes10 $total_size) if $total_size %>
</p>
</div>
diff --git a/templates/headers/_display_headers.html.ep b/templates/headers/_display_headers.html.ep
index f391259..42f927c 100644
--- a/templates/headers/_display_headers.html.ep
+++ b/templates/headers/_display_headers.html.ep
@@ -14,7 +14,7 @@
<thead>
<tr id=sort>
<th class="hide-small">
- No.
+ #
</th>
<th>
@@ -76,7 +76,7 @@
<!--
<div class="pure-u-1-4">
- %= ucfirst($msg->{is_multipart} ? l('yes') : l('no'));
+ %# ucfirst($msg->{is_multipart} ? l('yes') : l('no'));
</div>
-->
diff --git a/templates/headers/_pagination1.html.ep b/templates/headers/_pagination1.html.ep
index 010bdbd..9b6121a 100644
--- a/templates/headers/_pagination1.html.ep
+++ b/templates/headers/_pagination1.html.ep
@@ -1,7 +1,7 @@
<div>
<a href="<%= url_with->query({start => $prev_page->[0]-1}) %>"><img src="/left.gif" alt="←"></a>
<a href="<%= url_with->query({start => $first_page->[0]-1}) %>"><img src="/first.gif" alt="↞"></a>
- [<%= join(' ', ucfirst l('page'), $current_page, l('of'), $total_pages) %>]
+ [<%= l('page [_1] of [_2]', $current_page, $total_pages) %>]
<a href="<%= url_with->query({start => $last_page->[0]-1}) %>"><img src="/last.gif" alt="↠"></a>
<a href="<%= url_with->query({start => $next_page->[0]-1}) %>"><img src="/right.gif" alt="→"></a>
</div>
diff --git a/templates/webmail/displayheaders.html.ep b/templates/webmail/displayheaders.html.ep
index 42e52fd..23f48d3 100644
--- a/templates/webmail/displayheaders.html.ep
+++ b/templates/webmail/displayheaders.html.ep
@@ -17,7 +17,7 @@
% }
% else {
<p id=empty-folder>
- %= l 'empty_folder'
+ %= l 'This folder is empty!'
</p>
% }