New method to override messages with JSON files (#1595)
This commit is contained in:
parent
8ab1eb54bf
commit
8a9a5b0b3a
|
@ -332,7 +332,6 @@ site/templates/bootstrap/customhead.tpl
|
||||||
site/templates/bootstrap/customheader.tpl
|
site/templates/bootstrap/customheader.tpl
|
||||||
site/templates/bootstrap/customLoginFooter.tpl
|
site/templates/bootstrap/customLoginFooter.tpl
|
||||||
site/templates/bootstrap/customLoginHeader.tpl
|
site/templates/bootstrap/customLoginHeader.tpl
|
||||||
site/templates/bootstrap/error.json.example
|
|
||||||
site/templates/bootstrap/error.tpl
|
site/templates/bootstrap/error.tpl
|
||||||
site/templates/bootstrap/ext2fcheck.tpl
|
site/templates/bootstrap/ext2fcheck.tpl
|
||||||
site/templates/bootstrap/footer.tpl
|
site/templates/bootstrap/footer.tpl
|
||||||
|
@ -342,7 +341,6 @@ site/templates/bootstrap/idpchoice.tpl
|
||||||
site/templates/bootstrap/impersonation.tpl
|
site/templates/bootstrap/impersonation.tpl
|
||||||
site/templates/bootstrap/info.tpl
|
site/templates/bootstrap/info.tpl
|
||||||
site/templates/bootstrap/ldapPpGrace.tpl
|
site/templates/bootstrap/ldapPpGrace.tpl
|
||||||
site/templates/bootstrap/login.json
|
|
||||||
site/templates/bootstrap/login.tpl
|
site/templates/bootstrap/login.tpl
|
||||||
site/templates/bootstrap/mail.tpl
|
site/templates/bootstrap/mail.tpl
|
||||||
site/templates/bootstrap/menu.tpl
|
site/templates/bootstrap/menu.tpl
|
||||||
|
@ -400,7 +398,6 @@ site/templates/common/oidc_checksession.tpl
|
||||||
site/templates/common/redirect.tpl
|
site/templates/common/redirect.tpl
|
||||||
site/templates/common/registerBrowser.tpl
|
site/templates/common/registerBrowser.tpl
|
||||||
site/templates/common/script.tpl
|
site/templates/common/script.tpl
|
||||||
site/templates/common/trover.tpl
|
|
||||||
t/01-AuthDemo.t
|
t/01-AuthDemo.t
|
||||||
t/01-pdata.t
|
t/01-pdata.t
|
||||||
t/02-Password-Demo.t
|
t/02-Password-Demo.t
|
||||||
|
|
|
@ -734,38 +734,39 @@ sub _dump {
|
||||||
sub sendHtml {
|
sub sendHtml {
|
||||||
my ( $self, $req, $template, %args ) = @_;
|
my ( $self, $req, $template, %args ) = @_;
|
||||||
|
|
||||||
$args{params}->{TROVER} = $self->trOver;
|
my $templateDir = $self->conf->{templateDir} . '/' . $self->getSkin($req);
|
||||||
$args{templateDir} =
|
|
||||||
$self->conf->{templateDir} . '/' . $self->getSkin($req);
|
# Check template
|
||||||
my $tmpl = $args{templateDir} . "/$template.tpl";
|
$args{templateDir} = $templateDir;
|
||||||
my $troverJson = $args{templateDir} . "/$template.json";
|
my $tmpl = $args{templateDir} . "/$template.tpl";
|
||||||
unless ( -f $tmpl ) {
|
unless ( -f $tmpl ) {
|
||||||
$self->logger->debug("Template : $tmpl NOT found!!!");
|
$self->logger->debug("Template $tmpl not found");
|
||||||
$args{templateDir} = $self->conf->{templateDir} . '/bootstrap';
|
$args{templateDir} = $self->conf->{templateDir} . '/bootstrap';
|
||||||
$tmpl = $args{templateDir} . "/$template.tpl";
|
$tmpl = $args{templateDir} . "/$template.tpl";
|
||||||
$troverJson = $args{templateDir} . "/$template.json";
|
|
||||||
$self->logger->debug("-> Trying to load $tmpl");
|
$self->logger->debug("-> Trying to load $tmpl");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( -r $troverJson ) {
|
# Override messages
|
||||||
open my $tr_file, '<', $troverJson
|
my $trOverMessages = JSON::from_json( $self->trOver );
|
||||||
or die "Can't open" . $troverJson . " : $!";
|
|
||||||
while (<$tr_file>) {
|
opendir( DIR, $templateDir );
|
||||||
chomp;
|
my @langfiles = grep( /\.json$/, readdir(DIR) );
|
||||||
$args{params}->{TROVERbyJSON} .= $_;
|
close(DIR);
|
||||||
}
|
|
||||||
close $tr_file or die "Can't close $tr_file : $!";
|
foreach my $file (@langfiles) {
|
||||||
eval { decode_json( $args{params}->{TROVERbyJSON} ) };
|
my ($lang) = ( $file =~ /^(\w+)\.json/ );
|
||||||
if ($@) {
|
$self->logger->debug("Use $file to override messages");
|
||||||
$self->logger->debug("$troverJson is NOT a regular JSON file!!!");
|
if ( open my $json, "<", $templateDir . "/" . $file ) {
|
||||||
$args{params}->{TROVERbyJSON} = '';
|
local $/ = undef;
|
||||||
|
$trOverMessages->{$lang} = JSON::from_json(<$json>);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$self->logger->debug(" -> Overriding messages with $troverJson");
|
$self->logger->error("Unable to read $file");
|
||||||
$self->logger->debug(
|
|
||||||
" -> File content : $args{params}->{TROVERbyJSON}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$args{params}->{TROVER} = JSON::to_json($trOverMessages);
|
||||||
|
|
||||||
my $res = $self->SUPER::sendHtml( $req, $template, %args );
|
my $res = $self->SUPER::sendHtml( $req, $template, %args );
|
||||||
push @{ $res->[1] },
|
push @{ $res->[1] },
|
||||||
'X-XSS-Protection' => '1; mode=block',
|
'X-XSS-Protection' => '1; mode=block',
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"trOver":{"all":{},"fr":{"PE5":"Pas de chance, râté ! Merci de réessayer ..."},"en":{}}
|
|
||||||
}
|
|
|
@ -39,7 +39,6 @@
|
||||||
<link rel="openid2.provider" href="<TMPL_VAR NAME="PROVIDERURI">" />
|
<link rel="openid2.provider" href="<TMPL_VAR NAME="PROVIDERURI">" />
|
||||||
</TMPL_IF>
|
</TMPL_IF>
|
||||||
<TMPL_INCLUDE NAME="../common/script.tpl">
|
<TMPL_INCLUDE NAME="../common/script.tpl">
|
||||||
<TMPL_INCLUDE NAME="../common/trover.tpl">
|
|
||||||
<!-- //if:usedebianlibs
|
<!-- //if:usedebianlibs
|
||||||
<script type="text/javascript" src="<TMPL_VAR NAME="STATIC_PREFIX"><TMPL_VAR NAME="SKIN">/js/skin.min.js"></script>
|
<script type="text/javascript" src="<TMPL_VAR NAME="STATIC_PREFIX"><TMPL_VAR NAME="SKIN">/js/skin.min.js"></script>
|
||||||
<script type="text/javascript" src="<TMPL_VAR NAME="STATIC_PREFIX">common/js/portal.min.js"></script>
|
<script type="text/javascript" src="<TMPL_VAR NAME="STATIC_PREFIX">common/js/portal.min.js"></script>
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"trOver":{"all":{},"en":{"PE9":"You are welcome! Please login..."},"fr":{}}
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
<TMPL_IF NAME="TROVERbyJSON">
|
|
||||||
<script type="application/init">
|
|
||||||
<TMPL_VAR NAME="TROVERbyJSON">
|
|
||||||
</script>
|
|
||||||
</TMPL_IF>
|
|
|
@ -28,14 +28,9 @@ ok( $res->[2]->[0] =~ m%"trOver"%, ' trOver found' )
|
||||||
or print STDERR Dumper( $res->[2]->[0] );
|
or print STDERR Dumper( $res->[2]->[0] );
|
||||||
ok( $res->[2]->[0] =~ m%"all":\{\}%, ' all found' )
|
ok( $res->[2]->[0] =~ m%"all":\{\}%, ' all found' )
|
||||||
or print STDERR Dumper( $res->[2]->[0] );
|
or print STDERR Dumper( $res->[2]->[0] );
|
||||||
ok( $res->[2]->[0] =~ m%"en":\{"PE9":"You are welcome! Please login..."\}%,
|
|
||||||
' en found' )
|
|
||||||
or print STDERR Dumper( $res->[2]->[0] );
|
|
||||||
ok( $res->[2]->[0] =~ m%"fr":\{%, ' fr found' )
|
|
||||||
or print STDERR Dumper( $res->[2]->[0] );
|
|
||||||
ok( $res->[2]->[0] =~ m%"PE85":"From lemonlap-ng.ini"%, ' PE85 found' )
|
ok( $res->[2]->[0] =~ m%"PE85":"From lemonlap-ng.ini"%, ' PE85 found' )
|
||||||
or print STDERR Dumper( $res->[2]->[0] );
|
or print STDERR Dumper( $res->[2]->[0] );
|
||||||
count(7);
|
count(5);
|
||||||
|
|
||||||
# Try to authenticate
|
# Try to authenticate
|
||||||
# -------------------
|
# -------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user