From 519505e7f0904ad34cf56de544c6de7d1f2816e9 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 4 Sep 2020 18:46:16 +0400 Subject: [PATCH] Bug 26392: Wrap all translatable strings in opac-main.tt --- Koha/Template/Plugin/Expand.pm | 58 +++++++++++++++ .../intranet-tmpl/prog/en/includes/i18n.inc | 18 ++--- .../opac-tmpl/bootstrap/en/includes/i18n.inc | 18 ++--- .../bootstrap/en/modules/opac-main.tt | 73 ++++++++++++------- t/Koha/Template/Plugin/Expand.t | 11 +++ 5 files changed, 132 insertions(+), 46 deletions(-) create mode 100644 Koha/Template/Plugin/Expand.pm create mode 100755 t/Koha/Template/Plugin/Expand.t diff --git a/Koha/Template/Plugin/Expand.pm b/Koha/Template/Plugin/Expand.pm new file mode 100644 index 0000000000..055964622d --- /dev/null +++ b/Koha/Template/Plugin/Expand.pm @@ -0,0 +1,58 @@ +package Koha::Template::Plugin::Expand; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Koha::I18N; + +use base qw( Template::Plugin::Filter ); + +our $DYNAMIC = 1; + +=head1 SYNOPSIS + + [% USE Expand %] + [% PROCESS 'i18n.inc' %] + + [% t('Hello {name}') | html | $Expand name = "World !" %] + +=head1 DESCRIPTION + +This module is a Template::Toolkit filter that allows to replace portions of +text enclosed in braces by the content of a variable + +Its main purpose is to be used with i18n macros : it allows translations to be +filtered (with the html filter for instance) while allowing variables to have +content that should not be filtered + +=cut + +=head1 METHODS + +=head2 filter + +See L + +=cut + +sub filter { + my ( $self, $text, $args, $conf ) = @_; + + return Koha::I18N::_expand($text, %$conf); +} + +1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc index 3ad521e843..0a0f807127 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc @@ -2,37 +2,37 @@ [% USE raw %] [% MACRO t(msgid) BLOCK %] - [% I18N.t(msgid) | $raw %] + [%~ I18N.t(msgid) | $raw ~%] [% END %] [% MACRO tx(msgid, vars) BLOCK %] - [% I18N.tx(msgid, vars) | $raw %] + [%~ I18N.tx(msgid, vars) | $raw ~%] [% END %] [% MACRO tn(msgid, msgid_plural, count) BLOCK %] - [% I18N.tn(msgid, msgid_plural, count) | $raw %] + [%~ I18N.tn(msgid, msgid_plural, count) | $raw ~%] [% END %] [% MACRO tnx(msgid, msgid_plural, count, vars) BLOCK %] - [% I18N.tnx(msgid, msgid_plural, count, vars) | $raw %] + [%~ I18N.tnx(msgid, msgid_plural, count, vars) | $raw ~%] [% END %] [% MACRO txn(msgid, msgid_plural, count, vars) BLOCK %] - [% I18N.txn(msgid, msgid_plural, count, vars) | $raw %] + [%~ I18N.txn(msgid, msgid_plural, count, vars) | $raw ~%] [% END %] [% MACRO tp(msgctxt, msgid) BLOCK %] - [% I18N.tp(msgctxt, msgid) | $raw %] + [%~ I18N.tp(msgctxt, msgid) | $raw ~%] [% END %] [% MACRO tpx(msgctxt, msgid, vars) BLOCK %] - [% I18N.tpx(msgctxt, msgid, vars) | $raw %] + [%~ I18N.tpx(msgctxt, msgid, vars) | $raw ~%] [% END %] [% MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK %] - [% I18N.tnp(msgctxt, msgid, msgid_plural, count) | $raw %] + [%~ I18N.tnp(msgctxt, msgid, msgid_plural, count) | $raw ~%] [% END %] [% MACRO tnpx(msgctxt, msgid, msgid_plural, count, vars) BLOCK %] - [% I18N.tnpx(msgctxt, msgid, msgid_plural, count, vars) | $raw %] + [%~ I18N.tnpx(msgctxt, msgid, msgid_plural, count, vars) | $raw ~%] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/i18n.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/i18n.inc index 3ad521e843..0a0f807127 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/i18n.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/i18n.inc @@ -2,37 +2,37 @@ [% USE raw %] [% MACRO t(msgid) BLOCK %] - [% I18N.t(msgid) | $raw %] + [%~ I18N.t(msgid) | $raw ~%] [% END %] [% MACRO tx(msgid, vars) BLOCK %] - [% I18N.tx(msgid, vars) | $raw %] + [%~ I18N.tx(msgid, vars) | $raw ~%] [% END %] [% MACRO tn(msgid, msgid_plural, count) BLOCK %] - [% I18N.tn(msgid, msgid_plural, count) | $raw %] + [%~ I18N.tn(msgid, msgid_plural, count) | $raw ~%] [% END %] [% MACRO tnx(msgid, msgid_plural, count, vars) BLOCK %] - [% I18N.tnx(msgid, msgid_plural, count, vars) | $raw %] + [%~ I18N.tnx(msgid, msgid_plural, count, vars) | $raw ~%] [% END %] [% MACRO txn(msgid, msgid_plural, count, vars) BLOCK %] - [% I18N.txn(msgid, msgid_plural, count, vars) | $raw %] + [%~ I18N.txn(msgid, msgid_plural, count, vars) | $raw ~%] [% END %] [% MACRO tp(msgctxt, msgid) BLOCK %] - [% I18N.tp(msgctxt, msgid) | $raw %] + [%~ I18N.tp(msgctxt, msgid) | $raw ~%] [% END %] [% MACRO tpx(msgctxt, msgid, vars) BLOCK %] - [% I18N.tpx(msgctxt, msgid, vars) | $raw %] + [%~ I18N.tpx(msgctxt, msgid, vars) | $raw ~%] [% END %] [% MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK %] - [% I18N.tnp(msgctxt, msgid, msgid_plural, count) | $raw %] + [%~ I18N.tnp(msgctxt, msgid, msgid_plural, count) | $raw ~%] [% END %] [% MACRO tnpx(msgctxt, msgid, msgid_plural, count, vars) BLOCK %] - [% I18N.tnpx(msgctxt, msgid, msgid_plural, count, vars) | $raw %] + [%~ I18N.tnpx(msgctxt, msgid, msgid_plural, count, vars) | $raw ~%] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt index 2ae3796563..03d1e22dfd 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt @@ -1,3 +1,4 @@ +[% PROCESS 'i18n.inc' %] [% USE raw %] [% USE Koha %] [% USE KohaDates %] @@ -5,11 +6,12 @@ [% USE Categories %] [% USE Price %] [% USE KohaNews %] +[% USE Expand %] [% SET OpacNavRight = KohaNews.get( location => "OpacNavRight", lang => lang, library => branchcode ) %] [% SET OpacMainUserBlock = KohaNews.get( location => "OpacMainUserBlock", lang => lang, library => branchcode ) %] [% SET OpacLoginInstructions = KohaNews.get( location => "OpacLoginInstructions", lang => lang, library => branchcode ) %] [% INCLUDE 'doc-head-open.inc' %] -[% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog +[% IF ( LibraryNameTitle ) %][% tx('{LibraryNameTitle} catalog', LibraryNameTitle = LibraryNameTitle) | html %][% ELSE %][% t('Koha online catalog') | html %][% END %] [% INCLUDE 'doc-head-close.inc' %] [% BLOCK cssinclude %][% END %] @@ -18,7 +20,7 @@
@@ -112,15 +121,17 @@ [% IF Branches.all.size == 1 %] [% IF branchcode %] - RSS feed for [% Branches.GetName( branchcode ) | html %] library news + [% libraryName = BLOCK %][% Branches.GetName(branchcode) | html %][% END %] + [% t('RSS feed for {libraryName} library news') | html | $Expand libraryName = libraryName %] [% ELSE %] - RSS feed for library news + [% t('RSS feed for library news') | html %] [% END %] [% ELSE %] [% IF branchcode %] - RSS feed for [% Branches.GetName( branchcode ) | html %] and system-wide library news + [% libraryName = BLOCK %][% Branches.GetName(branchcode) | html %][% END %] + [% t('RSS feed for {libraryName} and system-wide library news') | html | $Expand libraryName = libraryName %] [% ELSE %] - RSS feed for system-wide library news + [% t('RSS feed for system-wide library news') | html %] [% END %] [% END %] @@ -134,7 +145,7 @@ [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %]
-
No news to display.
+
[% t('No news to display.') | html %]
@@ -145,7 +156,7 @@ [% UNLESS news_item # Don't show under single news item %] [% IF ( daily_quote ) %]
-

Quote of the day

+

[% t('Quote of the day') | html %]

[% daily_quote.text | html %] ~ [% daily_quote.source | html %]
@@ -170,11 +181,11 @@
- Log in to your account: - - + [% t('Log in to your account:') | html %] + +
- +
[% IF ( OpacLoginInstructions ) %]
@@ -183,12 +194,12 @@ [% END %] [% IF Koha.Preference('OpacPasswordChange') && Categories.can_any_reset_password %] [% END %] [% IF PatronSelfRegistration && PatronSelfRegistrationDefaultCategory %]
-

Don't have an account? Register here.

+

[% t('Don\'t have an account?') | html %] [% t('Register here.') | html %]

[% END %]
@@ -198,22 +209,28 @@ [% ELSE %] [% IF Koha.Preference('OPACUserSummary') && dashboard_info %]
-

Welcome, [% INCLUDE 'patron-title.inc' patron = logged_in_user %]

+ [% user = BLOCK %][% INCLUDE 'patron-title.inc' patron = logged_in_user %][% END %] +

[% t('Welcome, {user}') | html | $Expand user = user %]

diff --git a/t/Koha/Template/Plugin/Expand.t b/t/Koha/Template/Plugin/Expand.t new file mode 100755 index 0000000000..02959f1524 --- /dev/null +++ b/t/Koha/Template/Plugin/Expand.t @@ -0,0 +1,11 @@ +#!/usr/bin/env perl + +use Modern::Perl; + +use Test::More tests => 1; +use Koha::Template::Plugin::Expand; + +my $filter = Koha::Template::Plugin::Expand->new(); + +my $filtered = $filter->filter('Hello, {name}', [], { name => 'World!' }); +is($filtered, 'Hello, World!', '{name} was replaced by World!'); -- 2.20.1