diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2022-11-16 23:11:42 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2022-11-16 23:11:42 +0100 |
commit | a52a7d7c27440a7c2716af033a6113abcaa2bd46 (patch) | |
tree | 0b40912e689dfed35306558b3b41e6a98f169c39 /lib/JWebmail/Plugin/I18N2/Role.pm | |
parent | b36eada764601355be4616fb92822ffabdcb1dc8 (diff) |
split I18N2 plugin into multiple files and added translate role
Diffstat (limited to 'lib/JWebmail/Plugin/I18N2/Role.pm')
-rw-r--r-- | lib/JWebmail/Plugin/I18N2/Role.pm | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/JWebmail/Plugin/I18N2/Role.pm b/lib/JWebmail/Plugin/I18N2/Role.pm new file mode 100644 index 0000000..6ed75dc --- /dev/null +++ b/lib/JWebmail/Plugin/I18N2/Role.pm @@ -0,0 +1,39 @@ +package JWebmail::Plugin::I18N2::Role; + +use v5.22; +use warnings; +use utf8; + +use Role::Tiny; + +requires qw(translate); + + +sub languages { + require List::Util; + + my $self = shift; + my @ret = $self->loaded_languages; + + if (my $find = shift) { + return List::Util::any { $find eq $_ } @ret; + } + return wantarray ? sort @ret : @ret; +} + +1 + +__END__ + +=encoding utf-8 + +=head1 DESCRIPTION + +The translate method is called with self, the language and the word and +maybe additional arguments. + +The languages method shall report all loaded languages when called with no +argument and if a language is loaded when given an argument. + +A default languages method is provided that reads languages form the +loaded_language method. |