From 7880fc2f1446e703385f8b11664443ae71963a75 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 Signed-off-by: Owen Leonard --- Koha/Template/Plugin/Expand.pm | 58 +++++++++++++++++ koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc | 18 +++--- koha-tmpl/opac-tmpl/bootstrap/en/includes/i18n.inc | 18 +++--- .../opac-tmpl/bootstrap/en/modules/opac-main.tt | 75 +++++++++++++--------- t/Koha/Template/Plugin/Expand.t | 11 ++++ 5 files changed, 133 insertions(+), 47 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 3ee0709b3f..d08c886d45 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 %] @@ -21,14 +23,14 @@ @@ -68,12 +70,12 @@ [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %] [% UNLESS news_item %]
- + @@ -86,7 +88,7 @@ [% IF single_news_error %]
- This news item does not exist. + [% t('This news item does not exist.') | html %]
[% ELSE %] @@ -104,12 +106,19 @@
[% koha_new.content | $raw %]
- Published on [% koha_new.published_on | $KohaDates %] - [% IF ( (newsdisp == 'opac' || newsdisp == 'both') && koha_new.borrowernumber ) %] - by [% koha_new.author_title | html %] [% koha_new.author_firstname | html %] [% koha_new.author_surname | html %] + [% published_on = BLOCK %][% koha_new.published_on | $KohaDates %][% END %] + [% author = BLOCK %] + [% IF ( (newsdisp == 'opac' || newsdisp == 'both') && koha_new.borrowernumber ) %] + [% koha_new.author_title | html %] [% koha_new.author_firstname | html %] [% koha_new.author_surname | html %] + [% END %] + [% END %] + [% IF author %] + [% t('Published on {published_on} by {author}') | html | $Expand published_on = published_on, author = author %] + [% ELSE %] + [% t('Published on {published_on}') | html | $Expand published_on = published_on %] [% END %] [% IF ( news_item ) %] - • Show all news + • [% t('Show all news') | html %] [% END %]
@@ -122,15 +131,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 %] @@ -144,7 +155,7 @@ [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %]
-
No news to display.
+
[% t('No news to display.') | html %]
@@ -155,7 +166,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 %]
@@ -180,13 +191,13 @@
- Log in to your account: - + [% t('Log in to your account:') | html %] + - +
- +
[% IF ( OpacLoginInstructions ) %]
@@ -195,12 +206,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 %]
@@ -210,22 +221,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.11.0