From d1c6e70b446ff0f099f42e29352c5b718b36b0b1 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 25 Oct 2018 14:06:03 +0200 Subject: [PATCH] Bug 15395: Make QA test script happy It is not totally happy because of the template file used in tests. It has line breaks inside TT directives and QA test script complains because line breaks in TT directives confuse the current translatable strings extractor. However this patchset (along with bug 20988) will hopefully make the current extractor obsolete and thus make the 'no-line-breaks' rule useless Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens --- Koha/Template/Plugin/I18N.pm | 68 +++++++++++++++++++ .../intranet-tmpl/prog/en/includes/i18n.inc | 59 ++++++++-------- .../opac-tmpl/bootstrap/en/includes/i18n.inc | 59 ++++++++-------- t/LangInstaller/templates/simple.tt | 22 +++--- 4 files changed, 137 insertions(+), 71 deletions(-) diff --git a/Koha/Template/Plugin/I18N.pm b/Koha/Template/Plugin/I18N.pm index 8c95ea6d72..976c13927f 100644 --- a/Koha/Template/Plugin/I18N.pm +++ b/Koha/Template/Plugin/I18N.pm @@ -24,46 +24,114 @@ use base qw( Template::Plugin ); use C4::Context; use Koha::I18N; +=head1 NAME + +Koha::Template::Plugin::I18N - Translate strings in templates + +=head1 SYNOPSIS + +Do not use this plugin directly. Add the following directive + + [% PROCESS 'i18n.inc' %] + +and use the macros defined here + +=head1 METHODS + +=head2 t + + [% I18N.t("hello") %] + +=cut + sub t { my ($self, $msgid) = @_; return __($msgid); } +=head2 tx + + [% I18N.tx("hello {name}", { name = name }) %] + +=cut + sub tx { my ($self, $msgid, $vars) = @_; return __x($msgid, %$vars); } +=head2 tn + + [% I18N.tn("item", "items", count) %] + +=cut + sub tn { my ($self, $msgid, $msgid_plural, $count) = @_; return __n($msgid, $msgid_plural, $count); } +=head2 tnx + + [% I18N.tnx("{count} item", "{count} items", count, { count = count }) %] + +=cut + sub tnx { my ($self, $msgid, $msgid_plural, $count, $vars) = @_; return __nx($msgid, $msgid_plural, $count, %$vars); } +=head2 txn + +Alias of tnx + +=cut + sub txn { my ($self, $msgid, $msgid_plural, $count, $vars) = @_; return __xn($msgid, $msgid_plural, $count, %$vars); } +=head2 tp + + [% I18N.tp("context", "hello") %] + +=cut + sub tp { my ($self, $msgctxt, $msgid) = @_; return __p($msgctxt, $msgid); } +=head2 tpx + + [% I18N.tpx("context", "hello {name}", { name = name }) %] + +=cut + sub tpx { my ($self, $msgctxt, $msgid, $vars) = @_; return __px($msgctxt, $msgid, %$vars); } +=head2 tnp + + [% I18N.tnp("context", "item", "items") %] + +=cut + sub tnp { my ($self, $msgctxt, $msgid, $msgid_plural, $count) = @_; return __np($msgctxt, $msgid, $msgid_plural, $count); } +=head2 tnpx + + [% I18N.tnpx("context", "{count} item", "{count} items", { count = count }) %] + +=cut + sub tnpx { my ($self, $msgctxt, $msgid, $msgid_plural, $count, $vars) = @_; return __np($msgctxt, $msgid, $msgid_plural, $count, %$vars); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc index 4b5da9231b..3ad521e843 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc @@ -1,39 +1,38 @@ -[% - USE I18N; +[% USE I18N %] +[% USE raw %] - MACRO t(msgid) BLOCK; - I18N.t(msgid); - END; +[% MACRO t(msgid) BLOCK %] + [% I18N.t(msgid) | $raw %] +[% END %] - MACRO tx(msgid, vars) BLOCK; - I18N.tx(msgid, vars); - END; +[% MACRO tx(msgid, vars) BLOCK %] + [% I18N.tx(msgid, vars) | $raw %] +[% END %] - MACRO tn(msgid, msgid_plural, count) BLOCK; - I18N.tn(msgid, msgid_plural, count); - END; +[% MACRO tn(msgid, msgid_plural, count) BLOCK %] + [% I18N.tn(msgid, msgid_plural, count) | $raw %] +[% END %] - MACRO tnx(msgid, msgid_plural, count, vars) BLOCK; - I18N.tnx(msgid, msgid_plural, count, vars); - END; +[% MACRO tnx(msgid, msgid_plural, count, vars) BLOCK %] + [% I18N.tnx(msgid, msgid_plural, count, vars) | $raw %] +[% END %] - MACRO txn(msgid, msgid_plural, count, vars) BLOCK; - I18N.txn(msgid, msgid_plural, count, vars); - END; +[% MACRO txn(msgid, msgid_plural, count, vars) BLOCK %] + [% I18N.txn(msgid, msgid_plural, count, vars) | $raw %] +[% END %] - MACRO tp(msgctxt, msgid) BLOCK; - I18N.tp(msgctxt, msgid); - END; +[% MACRO tp(msgctxt, msgid) BLOCK %] + [% I18N.tp(msgctxt, msgid) | $raw %] +[% END %] - MACRO tpx(msgctxt, msgid, vars) BLOCK; - I18N.tpx(msgctxt, msgid, vars); - END; +[% MACRO tpx(msgctxt, msgid, vars) BLOCK %] + [% I18N.tpx(msgctxt, msgid, vars) | $raw %] +[% END %] - MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK; - I18N.tnp(msgctxt, msgid, msgid_plural, count); - END; +[% MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK %] + [% 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); - END; -%] +[% MACRO tnpx(msgctxt, msgid, msgid_plural, count, vars) BLOCK %] + [% 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 4b5da9231b..3ad521e843 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/i18n.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/i18n.inc @@ -1,39 +1,38 @@ -[% - USE I18N; +[% USE I18N %] +[% USE raw %] - MACRO t(msgid) BLOCK; - I18N.t(msgid); - END; +[% MACRO t(msgid) BLOCK %] + [% I18N.t(msgid) | $raw %] +[% END %] - MACRO tx(msgid, vars) BLOCK; - I18N.tx(msgid, vars); - END; +[% MACRO tx(msgid, vars) BLOCK %] + [% I18N.tx(msgid, vars) | $raw %] +[% END %] - MACRO tn(msgid, msgid_plural, count) BLOCK; - I18N.tn(msgid, msgid_plural, count); - END; +[% MACRO tn(msgid, msgid_plural, count) BLOCK %] + [% I18N.tn(msgid, msgid_plural, count) | $raw %] +[% END %] - MACRO tnx(msgid, msgid_plural, count, vars) BLOCK; - I18N.tnx(msgid, msgid_plural, count, vars); - END; +[% MACRO tnx(msgid, msgid_plural, count, vars) BLOCK %] + [% I18N.tnx(msgid, msgid_plural, count, vars) | $raw %] +[% END %] - MACRO txn(msgid, msgid_plural, count, vars) BLOCK; - I18N.txn(msgid, msgid_plural, count, vars); - END; +[% MACRO txn(msgid, msgid_plural, count, vars) BLOCK %] + [% I18N.txn(msgid, msgid_plural, count, vars) | $raw %] +[% END %] - MACRO tp(msgctxt, msgid) BLOCK; - I18N.tp(msgctxt, msgid); - END; +[% MACRO tp(msgctxt, msgid) BLOCK %] + [% I18N.tp(msgctxt, msgid) | $raw %] +[% END %] - MACRO tpx(msgctxt, msgid, vars) BLOCK; - I18N.tpx(msgctxt, msgid, vars); - END; +[% MACRO tpx(msgctxt, msgid, vars) BLOCK %] + [% I18N.tpx(msgctxt, msgid, vars) | $raw %] +[% END %] - MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK; - I18N.tnp(msgctxt, msgid, msgid_plural, count); - END; +[% MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK %] + [% 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); - END; -%] +[% MACRO tnpx(msgctxt, msgid, msgid_plural, count, vars) BLOCK %] + [% I18N.tnpx(msgctxt, msgid, msgid_plural, count, vars) | $raw %] +[% END %] diff --git a/t/LangInstaller/templates/simple.tt b/t/LangInstaller/templates/simple.tt index 5d8fb1084b..4b95636526 100644 --- a/t/LangInstaller/templates/simple.tt +++ b/t/LangInstaller/templates/simple.tt @@ -1,11 +1,11 @@ -[% t('hello') %] -[% tx('hello {name}', { name = 'Bob' }) %] -[% tn('item', 'items', count) %] -[% tnx('{count} item', '{count} items', count, { count = count }) %] -[% tp('context', 'hello') %] -[% tpx('context', 'hello {name}', { name = 'Bob' }) %] -[% tnp('context', 'item', 'items', count) %] -[% tnpx('context', '{count} item', '{count} items', count, { count = count }) %] +[% t('hello') | $raw %] +[% tx('hello {name}', { name = 'Bob' }) | $raw %] +[% tn('item', 'items', count) | $raw %] +[% tnx('{count} item', '{count} items', count, { count = count }) | $raw %] +[% tp('context', 'hello') | $raw %] +[% tpx('context', 'hello {name}', { name = 'Bob' }) | $raw %] +[% tnp('context', 'item', 'items', count) | $raw %] +[% tnpx('context', '{count} item', '{count} items', count, { count = count }) | $raw %] [% # it also works on multiple lines tnpx ( @@ -16,13 +16,13 @@ { count = count, } - ) + ) | $raw %] [% # and t* calls can be nested tx('status is {status}', { status = active ? t('active') : t('inactive') - }) + }) | $raw %] [%# but a TT comment won't get picked @@ -30,5 +30,5 @@ %] [% BLOCK %] - [% t('Inside block') %] + [% t('Inside block') | $raw %] [% END %] -- 2.39.5