package JWebmail::Plugin::I18N2::Maketext; use v5.24; use warnings; use utf8; use JWebmail::I18N; use Mojo::File qw(path curfile); use Role::Tiny::With; with 'JWebmail::Plugin::I18N2::Role'; sub new { my $class = shift; my $conf = @_ == 1 ? shift : {@_}; my $lexica = curfile->dirname->child('..', '..', 'I18N'); my $res = $lexica->list()->map('basename', '.pm'); my @languages = map { my ($l, $c) = split '_', $_, 2; $c ? "$l-\U$c" : $l } @$res; 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 $l = $conf->{log}) { $_->logger($l) for values %$self; } return bless $self, $class; } sub loaded_languages { grep { $_ !~ /^_/ } keys $_[0]->%* } sub translate { my $self = shift; my $lang = shift; my $phrase = shift; return $self->{$lang}->maketext($phrase, @_); } 1