~ubuntu-branches/ubuntu/trusty/libintl-perl/trusty

« back to all changes in this revision

Viewing changes to lib/Locale/Messages.pm

  • Committer: Package Import Robot
  • Author(s): Peter Eisentraut
  • Date: 2013-06-29 21:23:42 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20130629212342-3te0y4h5x26hb79b
Tags: 1.23-1
* New upstream release
* Updated standards version
* Changed to Debhelper level 9
* Added build-arch and build-indep targets
* Fixed application of Debian build flags for hardening

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /bin/false
2
2
 
3
3
# vim: set autoindent shiftwidth=4 tabstop=4:
4
 
# $Id$
5
4
 
6
 
# Copyright (C) 2002-2009 Guido Flohr <guido@imperia.net>,
 
5
# Copyright (C) 2002-2013 Guido Flohr <guido@imperia.net>,
7
6
# all rights reserved.
8
7
 
9
8
# This program is free software; you can redistribute it and/or modify it
27
26
 
28
27
use vars qw ($package @EXPORT_OK %EXPORT_TAGS @ISA $VERSION);
29
28
 
30
 
$VERSION = '1.20';
 
29
$VERSION = '1.23';
31
30
 
32
31
# Try to load the C version first.
33
32
$package = 'gettext_xs';
35
34
eval <<'EOF';
36
35
require Locale::gettext_xs; 
37
36
my $version = Locale::gettext_xs::__gettext_xs_version();
38
 
die "Version: $version mismatch (1.20 vs. $version)" unless $version eq '1.20';
 
37
die "Version: version mismatch ($VERSION vs. $version)" unless $version eq $VERSION;
39
38
EOF
40
39
if ($@) {
41
40
    $package = 'gettext_pp';
165
164
 
166
165
# The textdomain could be undef.  We avoid a warning by specifying
167
166
# a filter for the undefined textdomain.
168
 
my %filters = (
169
 
                           undef => \&turn_utf_8_off,
170
 
                           );
171
 
 
172
 
sub select_package
173
 
{
174
 
        my ($pkg, $compatibility) = @_;
175
 
 
176
 
        # Compatibility quirk for a bug pre 1.17:
177
 
        if (__PACKAGE__ eq $pkg && defined $compatibility) {
178
 
                $pkg = $compatibility;
179
 
        }
180
 
 
181
 
        if (!$can_xs || (defined $pkg && 'gettext_pp' eq $pkg)) {
182
 
                require Locale::gettext_pp;
183
 
                $package = 'gettext_pp';
184
 
        } else {
185
 
                eval "require Locale::gettext_xs";
186
 
                $package = 'gettext_xs' unless $@;
187
 
        }
 
167
my %filters = (undef => \&turn_utf_8_off);
 
168
 
 
169
sub select_package {
 
170
    my ($pkg, $compatibility) = @_;
 
171
 
 
172
    # Compatibility quirk for a bug pre 1.17:
 
173
    if (__PACKAGE__ eq $pkg && defined $compatibility) {
 
174
        $pkg = $compatibility;
 
175
    }
 
176
 
 
177
    if (!$can_xs && 'gettext_xs' eq $pkg) {
 
178
        $pkg = 'gettext_pp';
 
179
    }
 
180
 
 
181
    if (defined $pkg && 'gettext_pp' eq $pkg) {
 
182
        # This branch is not unnecessary.  The next (elsif) branch does
 
183
        # essentially the same but catches compilation errors.
 
184
        require Locale::gettext_pp;
 
185
        $package = 'gettext_pp';
 
186
    } elsif (defined $pkg) {
 
187
        my $filename = "Locale::$pkg";
 
188
        $filename =~ s{::|\'}{/};
 
189
        $filename .= '.pm';
 
190
        eval { require $filename };
 
191
        $package = $pkg unless $@;   
 
192
    } else {
 
193
        eval "require Locale::gettext_xs";
 
194
        $package = 'gettext_xs' unless $@;
 
195
    }
188
196
 
189
197
    return $package;
190
198
}
191
199
 
192
 
sub bind_textdomain_filter($;$$)
193
 
{
 
200
sub bind_textdomain_filter ($;$$) {
194
201
        my ($textdomain, $coderef, $data) = @_;
195
202
 
196
203
        $filters{$textdomain} = [ $coderef, $data ];
198
205
        return 1;
199
206
}
200
207
 
201
 
sub textdomain(;$)
202
 
{
203
 
    'gettext_xs' eq $package ?
204
 
        &Locale::gettext_xs::textdomain :
205
 
        &Locale::gettext_pp::textdomain;
206
 
}
207
 
 
208
 
sub bindtextdomain($;$)
209
 
{
210
 
    'gettext_xs' eq $package ?
211
 
        &Locale::gettext_xs::bindtextdomain :
212
 
        &Locale::gettext_pp::bindtextdomain;
213
 
}
214
 
 
215
 
sub bind_textdomain_codeset($;$)
216
 
{
217
 
    'gettext_xs' eq $package ?
218
 
        &Locale::gettext_xs::bind_textdomain_codeset :
219
 
        &Locale::gettext_pp::bind_textdomain_codeset;
220
 
}
221
 
 
222
 
sub gettext($)
223
 
{
224
 
        my $textdomain = textdomain;
225
 
        $filters{$textdomain} ||= [ \&turn_utf_8_off ];
226
 
        my $cb = $filters{$textdomain};
227
 
 
228
 
    $cb->[0] ('gettext_xs' eq $package ?
229
 
                     &Locale::gettext_xs::gettext :
230
 
                     &Locale::gettext_pp::gettext, $cb->[1]);
231
 
}
232
 
 
233
 
sub dgettext($$)
234
 
{
235
 
        my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
236
 
 
237
 
    $cb->[0] ('gettext_xs' eq $package ?
238
 
                     &Locale::gettext_xs::dgettext :
239
 
                     &Locale::gettext_pp::dgettext, $cb->[1]);
240
 
}
241
 
 
242
 
sub dcgettext($$$)
243
 
{
244
 
        my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
245
 
 
246
 
    $cb->[0] ('gettext_xs' eq $package ?
247
 
                     &Locale::gettext_xs::dcgettext :
248
 
                     &Locale::gettext_pp::dcgettext, $cb->[1]);
249
 
}
250
 
 
251
 
sub ngettext($$$)
252
 
{
253
 
        my $textdomain = textdomain;
254
 
        $filters{$textdomain} ||= [ \&turn_utf_8_off ];
255
 
        my $cb = $filters{$textdomain};
256
 
 
257
 
    $cb->[0] ('gettext_xs' eq $package ?
258
 
                     &Locale::gettext_xs::ngettext :
259
 
                     &Locale::gettext_pp::ngettext, $cb->[1]);
260
 
}
261
 
 
262
 
sub dngettext($$$$)
263
 
{
264
 
        my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
265
 
 
266
 
    $cb->[0] ('gettext_xs' eq $package ?
267
 
                     &Locale::gettext_xs::dngettext :
268
 
                     &Locale::gettext_pp::dngettext, $cb->[1]);
269
 
}
270
 
 
271
 
sub dcngettext($$$$$)
272
 
{
273
 
        my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
274
 
 
275
 
    $cb->[0] ('gettext_xs' eq $package ?
276
 
                     &Locale::gettext_xs::dcngettext :
277
 
                     &Locale::gettext_pp::dcngettext, $cb->[1]);
278
 
}
279
 
 
280
 
###
281
 
sub pgettext($$)
282
 
{
283
 
        my $textdomain = textdomain;
284
 
        $filters{$textdomain} ||= [ \&turn_utf_8_off ];
285
 
        my $cb = $filters{$textdomain};
286
 
 
287
 
    $cb->[0] ('gettext_xs' eq $package ?
288
 
                     &Locale::gettext_xs::pgettext :
289
 
                     &Locale::gettext_pp::pgettext, $cb->[1]);
290
 
}
291
 
 
292
 
sub dpgettext($$$)
293
 
{
294
 
        my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
295
 
 
296
 
    $cb->[0] ('gettext_xs' eq $package ?
297
 
                     &Locale::gettext_xs::dpgettext :
298
 
                     &Locale::gettext_pp::dpgettext, $cb->[1]);
299
 
}
300
 
 
301
 
sub dcpgettext($$$$)
302
 
{
303
 
        my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
304
 
 
305
 
    $cb->[0] ('gettext_xs' eq $package ?
306
 
                     &Locale::gettext_xs::dcpgettext :
307
 
                     &Locale::gettext_pp::dcpgettext, $cb->[1]);
308
 
}
309
 
 
310
 
sub npgettext($$$$)
311
 
{
312
 
        my $textdomain = textdomain;
313
 
        $filters{$textdomain} ||= [ \&turn_utf_8_off ];
314
 
        my $cb = $filters{$textdomain};
315
 
 
316
 
    $cb->[0] ('gettext_xs' eq $package ?
317
 
                     &Locale::gettext_xs::npgettext :
318
 
                     &Locale::gettext_pp::npgettext, $cb->[1]);
319
 
}
320
 
 
321
 
sub dnpgettext($$$$$)
322
 
{
323
 
        my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
324
 
 
325
 
    $cb->[0] ('gettext_xs' eq $package ?
326
 
                     &Locale::gettext_xs::dnpgettext :
327
 
                     &Locale::gettext_pp::dnpgettext, $cb->[1]);
328
 
}
329
 
 
330
 
sub dcnpgettext($$$$$$)
331
 
{
332
 
        my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
333
 
 
334
 
    $cb->[0] ('gettext_xs' eq $package ?
335
 
                     &Locale::gettext_xs::dcnpgettext :
336
 
                     &Locale::gettext_pp::dcnpgettext, $cb->[1]);
337
 
}
338
 
 
339
 
sub nl_putenv($)
340
 
{
341
 
    'gettext_xs' eq $package ?
342
 
                     &Locale::gettext_xs::nl_putenv :
343
 
                     &Locale::gettext_pp::nl_putenv;
344
 
}
345
 
 
346
 
sub LC_NUMERIC
347
 
{
348
 
    'gettext_xs' eq $package ?
349
 
        &Locale::gettext_xs::LC_NUMERIC :
350
 
        &Locale::gettext_pp::LC_NUMERIC;
351
 
}
352
 
 
353
 
sub LC_CTYPE
354
 
{
355
 
    'gettext_xs' eq $package ?
356
 
        &Locale::gettext_xs::LC_CTYPE :
357
 
        &Locale::gettext_pp::LC_CTYPE;
358
 
}
359
 
 
360
 
sub LC_TIME
361
 
{
362
 
    'gettext_xs' eq $package ?
363
 
        &Locale::gettext_xs::LC_TIME :
364
 
        &Locale::gettext_pp::LC_TIME;
365
 
}
366
 
 
367
 
sub LC_COLLATE
368
 
{
369
 
    'gettext_xs' eq $package ?
370
 
        &Locale::gettext_xs::LC_COLLATE :
371
 
        &Locale::gettext_pp::LC_COLLATE;
372
 
}
373
 
 
374
 
sub LC_MONETARY
375
 
{
376
 
    'gettext_xs' eq $package ?
377
 
        &Locale::gettext_xs::LC_MONETARY :
378
 
        &Locale::gettext_pp::LC_MONETARY;
379
 
}
380
 
 
381
 
sub LC_MESSAGES
382
 
{
383
 
    'gettext_xs' eq $package ?
384
 
        &Locale::gettext_xs::LC_MESSAGES :
385
 
        &Locale::gettext_pp::LC_MESSAGES;
386
 
}
387
 
 
388
 
sub LC_ALL
389
 
{
390
 
    'gettext_xs' eq $package ?
391
 
        &Locale::gettext_xs::LC_ALL :
392
 
        &Locale::gettext_pp::LC_ALL;
 
208
sub textdomain (;$) {
 
209
    my $function = "Locale::${package}::textdomain";
 
210
    
 
211
    no strict 'refs';
 
212
    &$function;
 
213
}
 
214
 
 
215
sub bindtextdomain ($;$) {
 
216
    my $function = "Locale::${package}::bindtextdomain";
 
217
 
 
218
    no strict 'refs';
 
219
    &$function;
 
220
}
 
221
 
 
222
sub bind_textdomain_codeset ($;$) {
 
223
    my $function = "Locale::${package}::bind_textdomain_codeset";
 
224
 
 
225
    no strict 'refs';    
 
226
    &$function;
 
227
}
 
228
 
 
229
sub gettext ($) {
 
230
    my $textdomain = textdomain;
 
231
    $filters{$textdomain} ||= [ \&turn_utf_8_off ];
 
232
    my $cb = $filters{$textdomain};
 
233
 
 
234
    my $function = "Locale::${package}::gettext";
 
235
    
 
236
    no strict 'refs';
 
237
    $cb->[0] (&$function, $cb->[1]);
 
238
}
 
239
 
 
240
sub dgettext($$) {
 
241
    my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
 
242
 
 
243
    my $function = "Locale::${package}::dgettext";
 
244
    
 
245
    no strict 'refs';
 
246
    $cb->[0] (&$function, $cb->[1]);
 
247
}
 
248
 
 
249
sub dcgettext($$$) {
 
250
    my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
 
251
 
 
252
    my $function = "Locale::${package}::dcgettext";
 
253
    
 
254
    no strict 'refs';
 
255
    $cb->[0] (&$function, $cb->[1]);
 
256
}
 
257
 
 
258
sub ngettext($$$) {
 
259
    my $textdomain = textdomain;
 
260
    $filters{$textdomain} ||= [ \&turn_utf_8_off ];
 
261
    my $cb = $filters{$textdomain};
 
262
 
 
263
    my $function = "Locale::${package}::ngettext";
 
264
    
 
265
    no strict 'refs';
 
266
    $cb->[0] (&$function, $cb->[1]);
 
267
}
 
268
 
 
269
sub dngettext($$$$) {
 
270
    my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
 
271
 
 
272
    my $function = "Locale::${package}::dngettext";
 
273
    
 
274
    no strict 'refs';
 
275
    $cb->[0] (&$function, $cb->[1]);
 
276
}
 
277
 
 
278
sub dcngettext($$$$$) {
 
279
    my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
 
280
 
 
281
    my $function = "Locale::${package}::dcngettext";
 
282
    
 
283
    no strict 'refs';
 
284
    $cb->[0] (&$function, $cb->[1]);
 
285
}
 
286
 
 
287
sub pgettext($$) {
 
288
    my $textdomain = textdomain;
 
289
    $filters{$textdomain} ||= [ \&turn_utf_8_off ];
 
290
    my $cb = $filters{$textdomain};
 
291
 
 
292
    my $function = "Locale::${package}::pgettext";
 
293
    
 
294
    no strict 'refs';
 
295
    $cb->[0] (&$function, $cb->[1]);
 
296
}
 
297
 
 
298
sub dpgettext($$$) {
 
299
    my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
 
300
 
 
301
    my $function = "Locale::${package}::dpgettext";
 
302
    
 
303
    no strict 'refs';
 
304
    $cb->[0] (&$function, $cb->[1]);
 
305
}
 
306
 
 
307
sub dcpgettext($$$$) {
 
308
    my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
 
309
 
 
310
    my $function = "Locale::${package}::dcpgettext";
 
311
    
 
312
    no strict 'refs';
 
313
    $cb->[0] (&$function, $cb->[1]);
 
314
}
 
315
 
 
316
sub npgettext($$$$) {
 
317
    my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
 
318
 
 
319
    my $function = "Locale::${package}::npgettext";
 
320
    
 
321
    no strict 'refs';
 
322
    $cb->[0] (&$function, $cb->[1]);
 
323
}
 
324
 
 
325
sub dnpgettext($$$$$) {
 
326
    my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
 
327
 
 
328
    my $function = "Locale::${package}::dnpgettext";
 
329
    
 
330
    no strict 'refs';
 
331
    $cb->[0] (&$function, $cb->[1]);
 
332
}
 
333
 
 
334
sub dcnpgettext($$$$$$) {
 
335
    my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
 
336
 
 
337
    my $function = "Locale::${package}::dcnpgettext";
 
338
    
 
339
    no strict 'refs';
 
340
    $cb->[0] (&$function, $cb->[1]);
 
341
}
 
342
 
 
343
sub nl_putenv($) {
 
344
    my $cb = $filters{$_[0]} ||= [ \&turn_utf_8_off ];
 
345
 
 
346
    my $function = "Locale::${package}::nl_putenv";
 
347
    
 
348
    no strict 'refs';
 
349
    &$function;
 
350
}
 
351
 
 
352
sub LC_NUMERIC {
 
353
    my $function = "Locale::${package}::LC_NUMERIC";
 
354
    
 
355
    no strict 'refs';
 
356
    &$function;
 
357
}
 
358
 
 
359
sub LC_CTYPE {
 
360
    my $function = "Locale::${package}::LC_CTYPE";
 
361
    
 
362
    no strict 'refs';
 
363
    &$function;
 
364
}
 
365
 
 
366
sub LC_TIME {
 
367
    my $function = "Locale::${package}::LC_TIME";
 
368
    
 
369
    no strict 'refs';
 
370
    &$function;
 
371
}
 
372
 
 
373
sub LC_COLLATE {
 
374
    my $function = "Locale::${package}::LC_COLLATE";
 
375
    
 
376
    no strict 'refs';
 
377
    &$function;
 
378
}
 
379
 
 
380
sub LC_MONETARY {
 
381
    my $function = "Locale::${package}::LC_MONETARY";
 
382
    
 
383
    no strict 'refs';
 
384
    &$function;
 
385
}
 
386
 
 
387
sub LC_MESSAGES {
 
388
    my $function = "Locale::${package}::LC_MESSAGES";
 
389
    
 
390
    no strict 'refs';
 
391
    &$function;
 
392
}
 
393
 
 
394
sub LC_ALL {
 
395
    my $function = "Locale::${package}::LC_ALL";
 
396
    
 
397
    no strict 'refs';
 
398
    &$function;
393
399
}
394
400
 
395
401
1;
494
500
change the order of the arguments, and a French translator could
495
501
then say:
496
502
 
497
 
    "C'est le %$2s %$1s."
 
503
    "C'est le %2$s %1$s."
498
504
 
499
505
Perl printf() implements this feature as of version 5.8 or better.
500
506
Consequently you can only use it, if you are sure that your software
769
775
The function was introduced with libintl-perl version 1.03 and is not
770
776
part of the standard gettext API.
771
777
 
 
778
Beginning with version 1.22 you can pass other package names than "gettext_pp"
 
779
or "gettext_xs" and use a completely different backend.  It is the caller's
 
780
responsability to make sure that the selected package offers the same
 
781
interface as the two standard packages.
 
782
 
 
783
One package that offers that functionality is Locale::gettext_dump(3pm).
 
784
 
772
785
=item B<nl_putenv ENVSPEC>
773
786
 
774
787
Resembles the ANSI C putenv(3) function.  The sole purpose of this 
998
1011
 
999
1012
=head1 AUTHOR
1000
1013
 
1001
 
Copyright (C) 2002-2009, Guido Flohr E<lt>guido@imperia.netE<gt>, all
 
1014
Copyright (C) 2002-2013, Guido Flohr E<lt>guido@imperia.netE<gt>, all
1002
1015
rights reserved.  See the source code for details.
1003
1016
 
1004
1017
This software is contributed to the Perl community by Imperia