1 package Koha::Template::Plugin::I18N;
3 # Copyright BibLibre 2015
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use base qw( Template::Plugin );
29 Koha::Template::Plugin::I18N - Translate strings in templates
33 [% PROCESS 'i18n.inc' %]
37 [% I18N.t("Hello!") %]
38 [% I18N.tx("Hello {name}", { name = name }) %]
39 [% I18N.tn("Hello friend", "Hello friends", count) %]
40 [% I18N.tnx("Hello my {count} friend", "Hello my {count} friends", count, { count = count }) %]
41 [% I18N.tp('verb', 'Item') # to order %]
42 [% I18N.tnp('bibliographic material', "item", "items", count) %]
43 [% I18N.tnpx('bibliographic material', "{count} item", "{count} items", count, { count = count }) %]
45 Do not use this plugin directly. Add the following directive
47 [% PROCESS 'i18n.inc' %]
49 and use the macros defined.
51 See: https://wiki.koha-community.org/wiki/Internationalization,_plural_forms,_context,_and_more_(RFC)
60 Translate - The simplest type of translatable string where
61 there are no variables and not pluralisations to consider.
66 my ($self, $msgid) = @_;
72 [% I18N.tx("hello {name}", { name = name }) %]
74 Translate with variable - A translatable string that
80 my ($self, $msgid, $vars) = @_;
81 return __x($msgid, %$vars);
86 [% I18N.tn("item", "items", count) %]
88 Translate with plural - A translatable string that needs
89 singular and plural forms
94 my ($self, $msgid, $msgid_plural, $count) = @_;
95 return __n($msgid, $msgid_plural, $count);
100 [% I18N.tnx("{count} item", "{count} items", count, { count = count }) %]
102 Translate with plural and variable - A translatable string
103 that needs singular and plural forms and includes a variable
108 my ($self, $msgid, $msgid_plural, $count, $vars) = @_;
109 return __nx($msgid, $msgid_plural, $count, %$vars);
119 my ($self, $msgid, $msgid_plural, $count, $vars) = @_;
120 return __xn($msgid, $msgid_plural, $count, %$vars);
125 [% I18N.tp("context", "hello") %]
127 Translate with context - A translatable string where a
128 context hint would be helpful to translators.
130 An example would be where in english a single word may be
131 be used as both a verb and a noun. You may want to add a
132 note to distinguish this particular use case so translators
133 can understand the context correctly.
138 my ($self, $msgctxt, $msgid) = @_;
139 return __p($msgctxt, $msgid);
144 [% I18N.tpx("context", "hello {name}", { name = name }) %]
146 Translate with context and variable - A translatable string
147 that needs both a contextual hint and includes a variable.
152 my ($self, $msgctxt, $msgid, $vars) = @_;
153 return __px($msgctxt, $msgid, %$vars);
158 [% I18N.tnp("context", "item", "items", count) %]
160 Translate with context and plural - A translatable string
161 that needs both a contextual hints and singular and plural
167 my ($self, $msgctxt, $msgid, $msgid_plural, $count) = @_;
168 return __np($msgctxt, $msgid, $msgid_plural, $count);
173 [% I18N.tnpx("context", "{count} item", "{count} items", count, { count = count }) %]
175 Translate with context, plural and variables - A translatable
176 string that needs contextual hints, singular and plural forms
177 and also includes variables.
182 my ($self, $msgctxt, $msgid, $msgid_plural, $count, $vars) = @_;
183 return __npx($msgctxt, $msgid, $msgid_plural, $count, %$vars);