From 44252e1e8a9559a0d53747e9637cd83e2d9f35cf 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 ++++++++++++ .../opac-tmpl/bootstrap/en/includes/i18n.inc | 18 ++-- .../bootstrap/en/modules/opac-main.tt | 94 ++++++++++--------- t/Koha/Template/Plugin/Expand.t | 11 +++ 4 files changed, 130 insertions(+), 51 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/opac-tmpl/bootstrap/en/includes/i18n.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/i18n.inc index 3ad521e843..269785005d 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 181fb9a0db..faa3a41e31 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt @@ -6,11 +6,12 @@ [% USE Price %] [% USE KohaNews %] [% PROCESS 'i18n.inc' %] +[% 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 %] @@ -22,14 +23,14 @@ @@ -69,12 +70,12 @@ [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %] [% UNLESS news_item %]
- + @@ -87,7 +88,7 @@ [% IF single_news_error %]
- This news item does not exist. + [% t('This news item does not exist.') | html %]
[% ELSE %] @@ -105,17 +106,23 @@
[% koha_new.content | $raw %]
- Published on [% koha_new.published_on | $KohaDates %] - [% IF ( (newsdisp == 'opac' || newsdisp == 'both') && koha_new.borrowernumber ) %] - [% IF news_item %] - [% SET author = koha_new.author %] - by [% author.title | html %] [% author.firstname | html %] [% author.surname | html %] - [% ELSE %] - 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 ) %] + [% IF news_item %] + [% koha_new.author.title | html %] [% koha_new.author.firstname | html %] [% koha_new.author.surname | html %] + [% ELSE %] + [% koha_new.author_title | html %] [% koha_new.author_firstname | html %] [% koha_new.author_surname | html %] + [% END %] [% 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 %]
@@ -128,15 +135,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 %] @@ -150,7 +159,7 @@ [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %]
-
No news to display.
+
[% t('No news to display.') | html %]
@@ -161,7 +170,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 %]
@@ -186,13 +195,13 @@
- Log in to your account: - + [% t('Log in to your account:') | html %] + - +
- +
[% IF ( OpacLoginInstructions ) %]
@@ -201,12 +210,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 %]
@@ -216,45 +225,46 @@ [% 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 %]