| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 Name |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
qbit::GetText |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 Description |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Functions to internatilization application. |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
More information on L. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
qbit::GetText use pure perl version of gettext by default. If you need to use XS version, set envirement variable FORCE_GETTEXT_XS to TRUE; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package qbit::GetText; |
|
17
|
|
|
|
|
|
|
$qbit::GetText::VERSION = '2.2'; |
|
18
|
8
|
|
|
8
|
|
25
|
use strict; |
|
|
8
|
|
|
|
|
9
|
|
|
|
8
|
|
|
|
|
183
|
|
|
19
|
8
|
|
|
8
|
|
24
|
use warnings; |
|
|
8
|
|
|
|
|
7
|
|
|
|
8
|
|
|
|
|
152
|
|
|
20
|
8
|
|
|
8
|
|
26
|
use utf8; |
|
|
8
|
|
|
|
|
5
|
|
|
|
8
|
|
|
|
|
28
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
8
|
|
|
8
|
|
196
|
use base qw(Exporter); |
|
|
8
|
|
|
|
|
695
|
|
|
|
8
|
|
|
|
|
489
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
8
|
|
|
8
|
|
3881
|
use Locale::Messages; |
|
|
8
|
|
|
|
|
94645
|
|
|
|
8
|
|
|
|
|
808
|
|
|
25
|
|
|
|
|
|
|
Locale::Messages->select_package($ENV{'FORCE_GETTEXT_XS'} ? 'gettext_xs' : 'gettext_pp'); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
BEGIN { |
|
28
|
8
|
|
|
8
|
|
12
|
our (@EXPORT, @EXPORT_OK); |
|
29
|
|
|
|
|
|
|
|
|
30
|
8
|
|
|
|
|
24
|
@EXPORT = qw( |
|
31
|
|
|
|
|
|
|
gettext ngettext pgettext npgettext |
|
32
|
|
|
|
|
|
|
d_gettext d_ngettext d_pgettext d_npgettext |
|
33
|
|
|
|
|
|
|
set_locale |
|
34
|
|
|
|
|
|
|
); |
|
35
|
8
|
|
|
|
|
3686
|
@EXPORT_OK = @EXPORT; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 Functions |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 gettext |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
B |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=over |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
B<$text> - string, message; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
B<@params> - array of strings, placeholders. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=back |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
B string, localized message. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub gettext($;@) { |
|
61
|
0
|
|
|
0
|
1
|
|
my ($text, @params) = @_; |
|
62
|
0
|
|
|
|
|
|
utf8::encode($text); |
|
63
|
0
|
|
|
|
|
|
my $msg = Locale::Messages::turn_utf_8_on(Locale::Messages::gettext($text)); |
|
64
|
0
|
0
|
|
|
|
|
return @params ? sprintf($msg, @params) : $msg; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 ngettext |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
B |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=over |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
B<$text> - string, message; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
B<$plural> - string, plural form of message; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
B<$n> - number, quantity of something; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
B<@params> - array of strings, placeholders. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
B string, localized message. |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub ngettext($$$;@) { |
|
96
|
0
|
|
|
0
|
1
|
|
my ($text, $plural, $n, @params) = @_; |
|
97
|
0
|
|
|
|
|
|
utf8::encode($text); |
|
98
|
0
|
|
|
|
|
|
utf8::encode($plural); |
|
99
|
0
|
|
|
|
|
|
my $msg = Locale::Messages::turn_utf_8_on(Locale::Messages::ngettext($text, $plural, $n)); |
|
100
|
0
|
0
|
|
|
|
|
return @params ? sprintf($msg, @params) : $msg; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 pgettext |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
B |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=over |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
B<$context> - string, message context; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
B<$text> - string, message; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
B<@params> - array of strings, placeholders. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=back |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
B string, localized message. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub pgettext($$;@) { |
|
128
|
0
|
|
|
0
|
1
|
|
my ($context, $text, @params) = @_; |
|
129
|
0
|
|
|
|
|
|
utf8::encode($context); |
|
130
|
0
|
|
|
|
|
|
utf8::encode($text); |
|
131
|
0
|
|
|
|
|
|
my $msg = Locale::Messages::turn_utf_8_on(Locale::Messages::pgettext($context, $text)); |
|
132
|
0
|
0
|
|
|
|
|
return @params ? sprintf($msg, @params) : $msg; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 npgettext |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
B |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
B<$context> - string, message context; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
B<$text> - string, message; |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
B<$plural> - string, plural form of message; |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
B<$n> - number, quantity of something; |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
B<@params> - array of strings, placeholders. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
B string, localized message. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub npgettext($$$$;@) { |
|
168
|
0
|
|
|
0
|
1
|
|
my ($context, $text, $plural, $n, @params) = @_; |
|
169
|
0
|
|
|
|
|
|
utf8::encode($context); |
|
170
|
0
|
|
|
|
|
|
utf8::encode($text); |
|
171
|
0
|
|
|
|
|
|
utf8::encode($plural); |
|
172
|
0
|
|
|
|
|
|
my $msg = Locale::Messages::turn_utf_8_on(Locale::Messages::npgettext($context, $text, $plural, $n)); |
|
173
|
0
|
0
|
|
|
|
|
return @params ? sprintf($msg, @params) : $msg; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 d_*gettext |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Deffered versions of *gettext functions. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
my $s = d_ngettext('site', 'sites', 1); |
|
181
|
|
|
|
|
|
|
# equivalent |
|
182
|
|
|
|
|
|
|
my $s = sub {ngettext('site', 'sites', 1)}; |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub d_gettext($;@) { |
|
187
|
0
|
|
|
0
|
0
|
|
my ($text, @params) = @_; |
|
188
|
0
|
|
|
0
|
|
|
return sub {gettext($text, @params)} |
|
189
|
0
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub d_ngettext($$$;@) { |
|
192
|
0
|
|
|
0
|
0
|
|
my ($text, $plural, $n, @params) = @_; |
|
193
|
|
|
|
|
|
|
|
|
194
|
0
|
|
|
0
|
|
|
return sub {ngettext($text, $plural, $n, @params)} |
|
195
|
0
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub d_pgettext($$;@) { |
|
198
|
0
|
|
|
0
|
0
|
|
my ($context, $text, @params) = @_; |
|
199
|
0
|
|
|
0
|
|
|
return sub {pgettext($context, $text, @params)}; |
|
|
0
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub d_npgettext($$$$;@) { |
|
203
|
0
|
|
|
0
|
0
|
|
my ($context, $text, $plural, $n, @params) = @_; |
|
204
|
|
|
|
|
|
|
|
|
205
|
0
|
|
|
0
|
|
|
return sub {npgettext($context, $text, $plural, $n, @params)} |
|
206
|
0
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 set_locale |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
B |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=over |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
B - string, locale (ru_RU, en_UK, ...); |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
B - string, path to locales; |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
B - string, project name. |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=back |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Path with locales must be C<$opts{'path'}/$opts{'lang'}/LC_MESSAGES/$opts{'project'}.mo>. |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub set_locale { |
|
233
|
0
|
|
|
0
|
1
|
|
my (%opts) = @_; |
|
234
|
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
|
Locale::Messages::nl_putenv("LC_ALL=$opts{'lang'}"); |
|
236
|
0
|
|
|
|
|
|
Locale::Messages::nl_putenv("LANGUAGE=$opts{'lang'}"); |
|
237
|
0
|
|
|
|
|
|
Locale::Messages::textdomain($opts{'project'}); |
|
238
|
0
|
|
|
|
|
|
Locale::Messages::bindtextdomain($opts{'project'} => $opts{'path'}); |
|
239
|
0
|
|
|
|
|
|
Locale::Messages::bind_textdomain_codeset($opts{'project'} => "UTF-8"); |
|
240
|
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
return 1; |
|
242
|
|
|
|
|
|
|
} |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
1; |