View | Details | Raw Unified | Return to bug 15395
Collapse All | Expand All

(-)a/Koha/Template/Plugin/I18N.pm (+68 lines)
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);
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc (-30 / +29 lines)
Lines 1-39 Link Here
1
[%
1
[% USE I18N %]
2
  USE I18N;
2
[% USE raw %]
3
3
4
  MACRO t(msgid) BLOCK;
4
[% MACRO t(msgid) BLOCK %]
5
    I18N.t(msgid);
5
    [% I18N.t(msgid) | $raw %]
6
  END;
6
[% END %]
7
7
8
  MACRO tx(msgid, vars) BLOCK;
8
[% MACRO tx(msgid, vars) BLOCK %]
9
    I18N.tx(msgid, vars);
9
    [% I18N.tx(msgid, vars) | $raw %]
10
  END;
10
[% END %]
11
11
12
  MACRO tn(msgid, msgid_plural, count) BLOCK;
12
[% MACRO tn(msgid, msgid_plural, count) BLOCK %]
13
    I18N.tn(msgid, msgid_plural, count);
13
    [% I18N.tn(msgid, msgid_plural, count) | $raw %]
14
  END;
14
[% END %]
15
15
16
  MACRO tnx(msgid, msgid_plural, count, vars) BLOCK;
16
[% MACRO tnx(msgid, msgid_plural, count, vars) BLOCK %]
17
    I18N.tnx(msgid, msgid_plural, count, vars);
17
    [% I18N.tnx(msgid, msgid_plural, count, vars) | $raw %]
18
  END;
18
[% END %]
19
19
20
  MACRO txn(msgid, msgid_plural, count, vars) BLOCK;
20
[% MACRO txn(msgid, msgid_plural, count, vars) BLOCK %]
21
    I18N.txn(msgid, msgid_plural, count, vars);
21
    [% I18N.txn(msgid, msgid_plural, count, vars) | $raw %]
22
  END;
22
[% END %]
23
23
24
  MACRO tp(msgctxt, msgid) BLOCK;
24
[% MACRO tp(msgctxt, msgid) BLOCK %]
25
    I18N.tp(msgctxt, msgid);
25
    [% I18N.tp(msgctxt, msgid) | $raw %]
26
  END;
26
[% END %]
27
27
28
  MACRO tpx(msgctxt, msgid, vars) BLOCK;
28
[% MACRO tpx(msgctxt, msgid, vars) BLOCK %]
29
    I18N.tpx(msgctxt, msgid, vars);
29
    [% I18N.tpx(msgctxt, msgid, vars) | $raw %]
30
  END;
30
[% END %]
31
31
32
  MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK;
32
[% MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK %]
33
    I18N.tnp(msgctxt, msgid, msgid_plural, count);
33
    [% I18N.tnp(msgctxt, msgid, msgid_plural, count) | $raw %]
34
  END;
34
[% END %]
35
35
36
  MACRO tnpx(msgctxt, msgid, msgid_plural, count, vars) BLOCK;
36
[% MACRO tnpx(msgctxt, msgid, msgid_plural, count, vars) BLOCK %]
37
    I18N.tnpx(msgctxt, msgid, msgid_plural, count, vars);
37
    [% I18N.tnpx(msgctxt, msgid, msgid_plural, count, vars) | $raw %]
38
  END;
38
[% END %]
39
%]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/i18n.inc (-30 / +29 lines)
Lines 1-39 Link Here
1
[%
1
[% USE I18N %]
2
  USE I18N;
2
[% USE raw %]
3
3
4
  MACRO t(msgid) BLOCK;
4
[% MACRO t(msgid) BLOCK %]
5
    I18N.t(msgid);
5
    [% I18N.t(msgid) | $raw %]
6
  END;
6
[% END %]
7
7
8
  MACRO tx(msgid, vars) BLOCK;
8
[% MACRO tx(msgid, vars) BLOCK %]
9
    I18N.tx(msgid, vars);
9
    [% I18N.tx(msgid, vars) | $raw %]
10
  END;
10
[% END %]
11
11
12
  MACRO tn(msgid, msgid_plural, count) BLOCK;
12
[% MACRO tn(msgid, msgid_plural, count) BLOCK %]
13
    I18N.tn(msgid, msgid_plural, count);
13
    [% I18N.tn(msgid, msgid_plural, count) | $raw %]
14
  END;
14
[% END %]
15
15
16
  MACRO tnx(msgid, msgid_plural, count, vars) BLOCK;
16
[% MACRO tnx(msgid, msgid_plural, count, vars) BLOCK %]
17
    I18N.tnx(msgid, msgid_plural, count, vars);
17
    [% I18N.tnx(msgid, msgid_plural, count, vars) | $raw %]
18
  END;
18
[% END %]
19
19
20
  MACRO txn(msgid, msgid_plural, count, vars) BLOCK;
20
[% MACRO txn(msgid, msgid_plural, count, vars) BLOCK %]
21
    I18N.txn(msgid, msgid_plural, count, vars);
21
    [% I18N.txn(msgid, msgid_plural, count, vars) | $raw %]
22
  END;
22
[% END %]
23
23
24
  MACRO tp(msgctxt, msgid) BLOCK;
24
[% MACRO tp(msgctxt, msgid) BLOCK %]
25
    I18N.tp(msgctxt, msgid);
25
    [% I18N.tp(msgctxt, msgid) | $raw %]
26
  END;
26
[% END %]
27
27
28
  MACRO tpx(msgctxt, msgid, vars) BLOCK;
28
[% MACRO tpx(msgctxt, msgid, vars) BLOCK %]
29
    I18N.tpx(msgctxt, msgid, vars);
29
    [% I18N.tpx(msgctxt, msgid, vars) | $raw %]
30
  END;
30
[% END %]
31
31
32
  MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK;
32
[% MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK %]
33
    I18N.tnp(msgctxt, msgid, msgid_plural, count);
33
    [% I18N.tnp(msgctxt, msgid, msgid_plural, count) | $raw %]
34
  END;
34
[% END %]
35
35
36
  MACRO tnpx(msgctxt, msgid, msgid_plural, count, vars) BLOCK;
36
[% MACRO tnpx(msgctxt, msgid, msgid_plural, count, vars) BLOCK %]
37
    I18N.tnpx(msgctxt, msgid, msgid_plural, count, vars);
37
    [% I18N.tnpx(msgctxt, msgid, msgid_plural, count, vars) | $raw %]
38
  END;
38
[% END %]
39
%]
(-)a/t/LangInstaller/templates/simple.tt (-12 / +11 lines)
Lines 1-11 Link Here
1
[% t('hello') %]
1
[% t('hello') | $raw %]
2
[% tx('hello {name}', { name = 'Bob' }) %]
2
[% tx('hello {name}', { name = 'Bob' }) | $raw %]
3
[% tn('item', 'items', count) %]
3
[% tn('item', 'items', count) | $raw %]
4
[% tnx('{count} item', '{count} items', count, { count = count }) %]
4
[% tnx('{count} item', '{count} items', count, { count = count }) | $raw %]
5
[% tp('context', 'hello') %]
5
[% tp('context', 'hello') | $raw %]
6
[% tpx('context', 'hello {name}', { name = 'Bob' }) %]
6
[% tpx('context', 'hello {name}', { name = 'Bob' }) | $raw %]
7
[% tnp('context', 'item', 'items', count) %]
7
[% tnp('context', 'item', 'items', count) | $raw %]
8
[% tnpx('context', '{count} item', '{count} items', count, { count = count }) %]
8
[% tnpx('context', '{count} item', '{count} items', count, { count = count }) | $raw %]
9
9
10
[% # it also works on multiple lines
10
[% # it also works on multiple lines
11
    tnpx (
11
    tnpx (
Lines 16-28 Link Here
16
        {
16
        {
17
            count = count,
17
            count = count,
18
        }
18
        }
19
    )
19
    ) | $raw
20
%]
20
%]
21
21
22
[% # and t* calls can be nested
22
[% # and t* calls can be nested
23
    tx('status is {status}', {
23
    tx('status is {status}', {
24
        status = active ? t('active') : t('inactive')
24
        status = active ? t('active') : t('inactive')
25
    })
25
    }) | $raw
26
%]
26
%]
27
27
28
[%# but a TT comment won't get picked
28
[%# but a TT comment won't get picked
Lines 30-34 Link Here
30
%]
30
%]
31
31
32
[% BLOCK %]
32
[% BLOCK %]
33
    [% t('Inside block') %]
33
    [% t('Inside block') | $raw %]
34
[% END %]
34
[% END %]
35
- 

Return to bug 15395