@@ -, +, @@ --- Koha/Template/Plugin/I18N.pm | 68 ++++++++++++++++++++++ koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc | 59 +++++++++---------- koha-tmpl/opac-tmpl/bootstrap/en/includes/i18n.inc | 59 +++++++++---------- t/LangInstaller/templates/simple.tt | 22 +++---- 4 files changed, 137 insertions(+), 71 deletions(-) --- a/Koha/Template/Plugin/I18N.pm +++ a/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); --- a/koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc +++ a/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 %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/i18n.inc +++ a/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 %] --- a/t/LangInstaller/templates/simple.tt +++ a/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 %] --