Merge branch 'fix-mail-trover-2772-2773' into 'v2.0'
Fix translation overrides See merge request lemonldap-ng/lemonldap-ng!282
This commit is contained in:
commit
621c88535a
|
@ -290,6 +290,9 @@ For example ``templates/myskin/en.json``:
|
||||||
You can also create a file called ``all.json`` to override messages in
|
You can also create a file called ``all.json`` to override messages in
|
||||||
all languages.
|
all languages.
|
||||||
|
|
||||||
|
.. versionchanged:: 2.0.15
|
||||||
|
Translations in lemonldap-ng.ini now take priority over translations from skin files
|
||||||
|
|
||||||
Menu tabs
|
Menu tabs
|
||||||
~~~~~~~~~
|
~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,22 @@ None
|
||||||
2.0.15
|
2.0.15
|
||||||
------
|
------
|
||||||
|
|
||||||
|
Translation overrides in lemonldap-ng.ini now take priority over skin
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Previously, the presence of a translation JSON file within a skin prevented
|
||||||
|
translation messages defined in ``lemonldap-ng.ini`` from being used.
|
||||||
|
|
||||||
|
Additionally, it was not possible to translate strings in email templates using
|
||||||
|
a custom skin file.
|
||||||
|
|
||||||
|
These two bugs are now fixed, be sure to check that you do not have duplicate
|
||||||
|
translations in ``lemonldap-ng.ini`` and in your skin files (``*.json``). If you do,
|
||||||
|
the translation in ``lemonldap-ng.ini`` will now take priority.
|
||||||
|
|
||||||
|
See :ref:`documentation on translating messages <intlmessages>` for
|
||||||
|
details
|
||||||
|
|
||||||
New Captcha API
|
New Captcha API
|
||||||
~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -73,8 +73,9 @@ sub translate {
|
||||||
. " ($self->{conf}->{templateDir}/$lang_code.json or $self->{conf}->{templateDir}/common/mail/en.json)";
|
. " ($self->{conf}->{templateDir}/$lang_code.json or $self->{conf}->{templateDir}/common/mail/en.json)";
|
||||||
$json = join '', <F>;
|
$json = join '', <F>;
|
||||||
close F;
|
close F;
|
||||||
my $lang = from_json( $json, { allow_nonref => 1 } );
|
my $lang = from_json( $json, { allow_nonref => 1 } );
|
||||||
my $langOver = from_json( $self->p->trOver, { allow_nonref => 1 } );
|
my $langOver =
|
||||||
|
from_json( $self->p->getTrOver($req), { allow_nonref => 1 } );
|
||||||
|
|
||||||
if ($langOver) {
|
if ($langOver) {
|
||||||
for my $k ( keys %{ $langOver->{all} || {} } ) {
|
for my $k ( keys %{ $langOver->{all} || {} } ) {
|
||||||
|
|
|
@ -872,6 +872,52 @@ sub _dump {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Warning: this function returns a JSON string
|
||||||
|
sub getTrOver {
|
||||||
|
my ( $self, $req, $templateDir ) = @_;
|
||||||
|
|
||||||
|
my $templateDir //= $self->conf->{templateDir} . '/' . $self->getSkin($req);
|
||||||
|
|
||||||
|
unless ( $self->trOverCache->{$templateDir} ) {
|
||||||
|
|
||||||
|
# Override messages
|
||||||
|
my $trOverMessages = JSON::from_json( $self->trOver );
|
||||||
|
|
||||||
|
opendir( DIR, $templateDir );
|
||||||
|
my @langfiles = grep( /\.json$/, readdir(DIR) );
|
||||||
|
close(DIR);
|
||||||
|
|
||||||
|
foreach my $file (@langfiles) {
|
||||||
|
my ($lang) = ( $file =~ /^(\w+)\.json/ );
|
||||||
|
$self->logger->debug("Use $file to override messages");
|
||||||
|
if ( open my $json, "<", $templateDir . "/" . $file ) {
|
||||||
|
my $trdata;
|
||||||
|
eval {
|
||||||
|
local $/ = undef;
|
||||||
|
$trdata = JSON::from_json(<$json>);
|
||||||
|
};
|
||||||
|
if ($@) {
|
||||||
|
$self->logger->warn("Ignoring $file because of error: $@");
|
||||||
|
}
|
||||||
|
if ( ref($trdata) eq "HASH" ) {
|
||||||
|
for my $msg ( keys %$trdata ) {
|
||||||
|
|
||||||
|
# lemonldap-ng.ini has priority
|
||||||
|
$trOverMessages->{$lang}->{$msg} //= $trdata->{$msg};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$self->logger->error("Unable to read $file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->trOverCache->{$templateDir} = JSON::to_json($trOverMessages);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $self->trOverCache->{$templateDir};
|
||||||
|
}
|
||||||
|
|
||||||
sub sendHtml {
|
sub sendHtml {
|
||||||
my ( $self, $req, $template, %args ) = @_;
|
my ( $self, $req, $template, %args ) = @_;
|
||||||
|
|
||||||
|
@ -888,29 +934,7 @@ sub sendHtml {
|
||||||
$self->logger->debug("-> Trying to load $tmpl");
|
$self->logger->debug("-> Trying to load $tmpl");
|
||||||
}
|
}
|
||||||
|
|
||||||
# Override messages
|
$args{params}->{TROVER} = $self->getTrOver( $req, $templateDir );
|
||||||
my $trOverMessages = JSON::from_json( $self->trOver );
|
|
||||||
|
|
||||||
unless ( $self->trOverCache->{$templateDir} ) {
|
|
||||||
opendir( DIR, $templateDir );
|
|
||||||
my @langfiles = grep( /\.json$/, readdir(DIR) );
|
|
||||||
close(DIR);
|
|
||||||
|
|
||||||
foreach my $file (@langfiles) {
|
|
||||||
my ($lang) = ( $file =~ /^(\w+)\.json/ );
|
|
||||||
$self->logger->debug("Use $file to override messages");
|
|
||||||
if ( open my $json, "<", $templateDir . "/" . $file ) {
|
|
||||||
local $/ = undef;
|
|
||||||
$trOverMessages->{$lang} = JSON::from_json(<$json>);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$self->logger->error("Unable to read $file");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->trOverCache->{$templateDir} = JSON::to_json($trOverMessages);
|
|
||||||
}
|
|
||||||
$args{params}->{TROVER} = $self->trOverCache->{$templateDir};
|
|
||||||
|
|
||||||
my $res = $self->SUPER::sendHtml( $req, $template, %args );
|
my $res = $self->SUPER::sendHtml( $req, $template, %args );
|
||||||
push @{ $res->[1] },
|
push @{ $res->[1] },
|
||||||
|
|
Loading…
Reference in New Issue