Bugzilla – Attachment 109947 Details for
Bug 26392
Wrap all translatable strings in opac-main.tt
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26392: Wrap all translatable strings in opac-main.tt
Bug-26392-Wrap-all-translatable-strings-in-opac-ma.patch (text/plain), 21.35 KB, created by
Owen Leonard
on 2020-09-11 14:23:22 UTC
(
hide
)
Description:
Bug 26392: Wrap all translatable strings in opac-main.tt
Filename:
MIME Type:
Creator:
Owen Leonard
Created:
2020-09-11 14:23:22 UTC
Size:
21.35 KB
patch
obsolete
>From 7880fc2f1446e703385f8b11664443ae71963a75 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >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 <oleonard@myacpl.org> >--- > 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 <http://www.gnu.org/licenses>. >+ >+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 = "<strong>World !</strong>" %] >+ >+=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<Template::Plugin::Filter> >+ >+=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' %] >-<title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog</title> >+<title>[% IF ( LibraryNameTitle ) %][% tx('{LibraryNameTitle} catalog', LibraryNameTitle = LibraryNameTitle) | html %][% ELSE %][% t('Koha online catalog') | html %][% END %]</title> > [% INCLUDE 'doc-head-close.inc' %] > [% BLOCK cssinclude %][% END %] > </head> >@@ -21,14 +23,14 @@ > <ul class="breadcrumb"> > [% IF news_item %] > <li class="breadcrumb-item"> >- <a href="/cgi-bin/koha/opac-main.pl">Home</a> >+ <a href="/cgi-bin/koha/opac-main.pl">[% t('Home') | html %]</a> > </li> > <li class="breadcrumb-item active" aria-current="page"> > [% news_item.title | html %] > </li> > [% ELSE %] > <li class="breadcrumb-item active" aria-current="page"> >- <a href="/cgi-bin/koha/opac-main.pl">Home</a> >+ <a href="/cgi-bin/koha/opac-main.pl">[% t('Home') | html %]</a> > </li> > [% END %] > </ul> >@@ -68,12 +70,12 @@ > [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %] > [% UNLESS news_item %] > <form id="news-branch-select" class="form-inline" name="news-branch-select" method="get" action="/cgi-bin/koha/opac-main.pl"> >- <label for="news-branch">Display news for: </label> >+ <label for="news-branch">[% t('Display news for:') | html %] </label> > <select id="news-branch" name="branch"> > [% IF ( branchcode == "" ) %] >- <option value="" selected="selected">System-wide only</option> >+ <option value="" selected="selected">[% t('System-wide only') | html %]</option> > [% ELSE %] >- <option value="">System-wide only</option> >+ <option value="">[% t('System-wide only') | html %]</option> > [% END %] > [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode, unfiltered => 1, ) %] > </select> >@@ -86,7 +88,7 @@ > [% IF single_news_error %] > > <div class="alert alert-error"> >- This news item does not exist. >+ [% t('This news item does not exist.') | html %] > </div> > > [% ELSE %] >@@ -104,12 +106,19 @@ > </h4> > <div class="newsbody">[% koha_new.content | $raw %]</div> > <div class="newsfooter"> >- Published on [% koha_new.published_on | $KohaDates %] >- [% IF ( (newsdisp == 'opac' || newsdisp == 'both') && koha_new.borrowernumber ) %] >- by <span class="newsauthor_title">[% koha_new.author_title | html %] </span>[% 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 ) %] >+ <span class="newsauthor_title">[% koha_new.author_title | html %] </span>[% 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 ) %] >- • <a href="/cgi-bin/koha/opac-main.pl">Show all news</a> >+ • <a href="/cgi-bin/koha/opac-main.pl">[% t('Show all news') | html %]</a> > [% END %] > </div> > </div> >@@ -122,15 +131,17 @@ > <i class="fa fa-rss" aria-hidden="true"></i> > [% 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 %] > </a> >@@ -144,7 +155,7 @@ > [% IF Koha.Preference( 'OpacNewsLibrarySelect' ) %] > <div id="news" class="newscontainer"> > <div class="newsitem"> >- <div class="newsbody">No news to display.</div> >+ <div class="newsbody">[% t('No news to display.') | html %]</div> > <div class="newsfooter"></div> > </div> > </div> >@@ -155,7 +166,7 @@ > [% UNLESS news_item # Don't show under single news item %] > [% IF ( daily_quote ) %] > <div id="daily-quote"> >- <h3>Quote of the day</h3> >+ <h3>[% t('Quote of the day') | html %]</h3> > <div> > <span id="daily-quote-text">[% daily_quote.text | html %]</span><span id="daily-quote-sep"> ~ </span><span id="daily-quote-source">[% daily_quote.source | html %]</span> > </div> >@@ -180,13 +191,13 @@ > <form action="/cgi-bin/koha/opac-user.pl" method="post" name="auth" id="auth" autocomplete="off"> > <input type="hidden" name="koha_login_context" value="opac" /> > <fieldset class="brief"> >- <legend>Log in to your account:</legend> >- <label for="userid">Login:</label> >+ <legend>[% t('Log in to your account:') | html %]</legend> >+ <label for="userid">[% t('Login:') | html %]</label> > <input class="form-control" type="text" id="userid" name="userid" /> >- <label for="password">Password:</label> >+ <label for="password">[% t('Password:') | html %]</label> > <input class="form-control" type="password" id="password" name="password" /> > <fieldset class="action"> >- <input type="submit" value="Log in" class="btn btn-primary" /> >+ <input type="submit" value="[% t('Log in') | html %]" class="btn btn-primary" /> > </fieldset> > [% IF ( OpacLoginInstructions ) %] > <div id="nologininstructions-main" class="nologininstructions"> >@@ -195,12 +206,12 @@ > [% END %] > [% IF Koha.Preference('OpacPasswordChange') && Categories.can_any_reset_password %] > <div id="forgotpassword-main" class="forgotpassword"> >- <p><a href="/cgi-bin/koha/opac-password-recovery.pl">Forgot your password?</a></p> >+ <p><a href="/cgi-bin/koha/opac-password-recovery.pl">[% t('Forgot your password?') | html %]</a></p> > </div> > [% END %] > [% IF PatronSelfRegistration && PatronSelfRegistrationDefaultCategory %] > <div id="patronregistration-main" class="patronregistration"> >- <p>Don't have an account? <a href="/cgi-bin/koha/opac-memberentry.pl">Register here.</a></p> >+ <p>[% t('Don\'t have an account?') | html %] <a href="/cgi-bin/koha/opac-memberentry.pl">[% t('Register here.') | html %]</a></p> > </div> > [% END %] > </fieldset> >@@ -210,22 +221,28 @@ > [% ELSE %] > [% IF Koha.Preference('OPACUserSummary') && dashboard_info %] > <div id="user_summary"> >- <h3>Welcome, <a href="/cgi-bin/koha/opac-user.pl"><span class="loggedinusername">[% INCLUDE 'patron-title.inc' patron = logged_in_user %]</span></a></h3> >+ [% user = BLOCK %]<a href="/cgi-bin/koha/opac-user.pl"><span class="loggedinusername">[% INCLUDE 'patron-title.inc' patron = logged_in_user %]</span></a>[% END %] >+ <h3>[% t('Welcome, {user}') | html | $Expand user = user %]</h3> > <ul id="user_summary_shortcuts"> > [% IF checkouts && checkouts > 0 %] >- <li><a href="/cgi-bin/koha/opac-user.pl#opac-user-checkouts"><span class="user_checkouts_count count_label">[% checkouts | html %]</span> checkout(s)</a></li> >+ [% count = BLOCK %]<span class="user_checkouts_count count_label">[% checkouts | html %]</span>[% END %] >+ <li><a href="/cgi-bin/koha/opac-user.pl#opac-user-checkouts">[% tn('{count} checkout', '{count} checkouts', checkouts) | html | $Expand count = count %]</a></li> > [% END %] > [% IF overdues && overdues > 0 %] >- <li><a href="/cgi-bin/koha/opac-user.pl#opac-user-overdues"><span class="user_overdues_count count_label">[% overdues | html %]</span> overdue(s)</a></li> >+ [% count = BLOCK %]<span class="user_overdues_count count_label">[% overdues | html %]</span>[% END %] >+ <li><a href="/cgi-bin/koha/opac-user.pl#opac-user-overdues">[% tn('{count} overdue', '{count} overdues', overdues) | html | $Expand count = count %]</a></li> > [% END %] > [% IF holds_pending && holds_pending > 0 %] >- <li><a href="/cgi-bin/koha/opac-user.pl#opac-user-holds"><span class="user_holds_pending_count count_label">[% holds_pending | html %]</span> hold(s) pending</a></li> >+ [% count = BLOCK %]<span class="user_holds_pending_count count_label">[% holds_pending | html %]</span>[% END %] >+ <li><a href="/cgi-bin/koha/opac-user.pl#opac-user-holds">[% tn('{count} hold pending', '{count} holds pending', holds_pending) | html | $Expand count = count %]</a></li> > [% END %] > [% IF holds_waiting && holds_waiting > 0 %] >- <li><a href="/cgi-bin/koha/opac-user.pl#opac-user-holds"><span class="user_holds_waiting_count count_label">[% holds_waiting | html %]</span> hold(s) waiting</a></li> >+ [% count = BLOCK %]<span class="user_holds_waiting_count count_label">[% holds_waiting | html %]</span>[% END %] >+ <li><a href="/cgi-bin/koha/opac-user.pl#opac-user-holds">[% tn('{count} hold waiting', '{count} holds waiting', holds_waiting) | html | $Expand count = count %]</a></li> > [% END %] > [% IF total_owing && total_owing > 0 %] >- <li><a href="/cgi-bin/koha/opac-account.pl"><span class="user_fines_count count_label">[% total_owing | $Price with_symbol => 1 %]</span> due in fines and charges</a></li> >+ [% amount = BLOCK %]<span class="user_fines_count count_label">[% total_owing | $Price with_symbol => 1 %]</span>[% END %] >+ <li><a href="/cgi-bin/koha/opac-account.pl">[% t('{amount} due in fines and charges') | html | $Expand amount = amount %]</a></li> > [% END %] > </ul> > </div> >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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26392
:
109666
|
109943
|
109944
|
109947
|
109948
|
117794
|
117795