Lines 24-69
use base qw( Template::Plugin );
Link Here
|
24 |
use C4::Context; |
24 |
use C4::Context; |
25 |
use Koha::I18N; |
25 |
use Koha::I18N; |
26 |
|
26 |
|
|
|
27 |
=head1 NAME |
28 |
|
29 |
Koha::Template::Plugin::I18N - Translate strings in templates |
30 |
|
31 |
=head1 SYNOPSIS |
32 |
|
33 |
Do not use this plugin directly. Add the following directive |
34 |
|
35 |
[% PROCESS 'i18n.inc' %] |
36 |
|
37 |
and use the macros defined here |
38 |
|
39 |
=head1 METHODS |
40 |
|
41 |
=head2 t |
42 |
|
43 |
[% I18N.t("hello") %] |
44 |
|
45 |
=cut |
46 |
|
27 |
sub t { |
47 |
sub t { |
28 |
my ($self, $msgid) = @_; |
48 |
my ($self, $msgid) = @_; |
29 |
return __($msgid); |
49 |
return __($msgid); |
30 |
} |
50 |
} |
31 |
|
51 |
|
|
|
52 |
=head2 tx |
53 |
|
54 |
[% I18N.tx("hello {name}", { name = name }) %] |
55 |
|
56 |
=cut |
57 |
|
32 |
sub tx { |
58 |
sub tx { |
33 |
my ($self, $msgid, $vars) = @_; |
59 |
my ($self, $msgid, $vars) = @_; |
34 |
return __x($msgid, %$vars); |
60 |
return __x($msgid, %$vars); |
35 |
} |
61 |
} |
36 |
|
62 |
|
|
|
63 |
=head2 tn |
64 |
|
65 |
[% I18N.tn("item", "items", count) %] |
66 |
|
67 |
=cut |
68 |
|
37 |
sub tn { |
69 |
sub tn { |
38 |
my ($self, $msgid, $msgid_plural, $count) = @_; |
70 |
my ($self, $msgid, $msgid_plural, $count) = @_; |
39 |
return __n($msgid, $msgid_plural, $count); |
71 |
return __n($msgid, $msgid_plural, $count); |
40 |
} |
72 |
} |
41 |
|
73 |
|
|
|
74 |
=head2 tnx |
75 |
|
76 |
[% I18N.tnx("{count} item", "{count} items", count, { count = count }) %] |
77 |
|
78 |
=cut |
79 |
|
42 |
sub tnx { |
80 |
sub tnx { |
43 |
my ($self, $msgid, $msgid_plural, $count, $vars) = @_; |
81 |
my ($self, $msgid, $msgid_plural, $count, $vars) = @_; |
44 |
return __nx($msgid, $msgid_plural, $count, %$vars); |
82 |
return __nx($msgid, $msgid_plural, $count, %$vars); |
45 |
} |
83 |
} |
46 |
|
84 |
|
|
|
85 |
=head2 txn |
86 |
|
87 |
Alias of tnx |
88 |
|
89 |
=cut |
90 |
|
47 |
sub txn { |
91 |
sub txn { |
48 |
my ($self, $msgid, $msgid_plural, $count, $vars) = @_; |
92 |
my ($self, $msgid, $msgid_plural, $count, $vars) = @_; |
49 |
return __xn($msgid, $msgid_plural, $count, %$vars); |
93 |
return __xn($msgid, $msgid_plural, $count, %$vars); |
50 |
} |
94 |
} |
51 |
|
95 |
|
|
|
96 |
=head2 tp |
97 |
|
98 |
[% I18N.tp("context", "hello") %] |
99 |
|
100 |
=cut |
101 |
|
52 |
sub tp { |
102 |
sub tp { |
53 |
my ($self, $msgctxt, $msgid) = @_; |
103 |
my ($self, $msgctxt, $msgid) = @_; |
54 |
return __p($msgctxt, $msgid); |
104 |
return __p($msgctxt, $msgid); |
55 |
} |
105 |
} |
56 |
|
106 |
|
|
|
107 |
=head2 tpx |
108 |
|
109 |
[% I18N.tpx("context", "hello {name}", { name = name }) %] |
110 |
|
111 |
=cut |
112 |
|
57 |
sub tpx { |
113 |
sub tpx { |
58 |
my ($self, $msgctxt, $msgid, $vars) = @_; |
114 |
my ($self, $msgctxt, $msgid, $vars) = @_; |
59 |
return __px($msgctxt, $msgid, %$vars); |
115 |
return __px($msgctxt, $msgid, %$vars); |
60 |
} |
116 |
} |
61 |
|
117 |
|
|
|
118 |
=head2 tnp |
119 |
|
120 |
[% I18N.tnp("context", "item", "items") %] |
121 |
|
122 |
=cut |
123 |
|
62 |
sub tnp { |
124 |
sub tnp { |
63 |
my ($self, $msgctxt, $msgid, $msgid_plural, $count) = @_; |
125 |
my ($self, $msgctxt, $msgid, $msgid_plural, $count) = @_; |
64 |
return __np($msgctxt, $msgid, $msgid_plural, $count); |
126 |
return __np($msgctxt, $msgid, $msgid_plural, $count); |
65 |
} |
127 |
} |
66 |
|
128 |
|
|
|
129 |
=head2 tnpx |
130 |
|
131 |
[% I18N.tnpx("context", "{count} item", "{count} items", { count = count }) %] |
132 |
|
133 |
=cut |
134 |
|
67 |
sub tnpx { |
135 |
sub tnpx { |
68 |
my ($self, $msgctxt, $msgid, $msgid_plural, $count, $vars) = @_; |
136 |
my ($self, $msgctxt, $msgid, $msgid_plural, $count, $vars) = @_; |
69 |
return __np($msgctxt, $msgid, $msgid_plural, $count, %$vars); |
137 |
return __np($msgctxt, $msgid, $msgid_plural, $count, %$vars); |