line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gettext; |
2
|
1
|
|
|
1
|
|
645
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
372
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
8
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
93
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1240
|
use POSIX 'locale_h'; |
|
1
|
|
|
|
|
9658
|
|
|
1
|
|
|
|
|
9
|
|
7
|
1
|
|
|
1
|
|
3673
|
use locale; |
|
1
|
|
|
|
|
286
|
|
|
1
|
|
|
|
|
5
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
require AutoLoader; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw(Exporter AutoLoader); |
13
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
14
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
15
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
16
|
|
|
|
|
|
|
@EXPORT = qw( ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$VERSION = '0.01'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Preloaded methods go here. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $gettextcmd = ( -e '/bin/gettext' ? '/bin/gettext' : '/usr/bin/gettext' ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
28
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
29
|
0
|
|
|
|
|
|
my $self = {}; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
0
|
|
|
|
$self->{'DOMAINNAME'} = untaint($ENV{'DOMAINNAME'}) || 'messages'; |
32
|
0
|
|
0
|
|
|
|
$self->{'DIRNAME'} = untaint($ENV{'TEXTDOMAINDIR'}) || ( -d '/usr/lib/locale' ? '/usr/lib/locale' : '/usr/share/locale' ); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
bless($self, $class); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub bindtextdomain { |
40
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
41
|
0
|
|
|
|
|
|
my ($domainname, $dirname) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
0
|
|
|
|
return '' if not defined $domainname or $domainname eq ''; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
0
|
|
|
|
return $self->{'DIRNAME'} if not defined $dirname or $dirname eq ''; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$self->{'DOMAINNAME'} = $domainname; |
48
|
0
|
|
|
|
|
|
$self->{'DIRNAME'} = $dirname; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return $dirname; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub textdomain { |
54
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
55
|
0
|
|
|
|
|
|
my ($domainname) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
return $self->{'DOMAINNAME'} if not defined $domainname; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ($domainname eq '') { |
60
|
0
|
|
|
|
|
|
$self->{'DOMAINNAME'} = 'messages' |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
|
|
|
|
|
|
# really should be input validation for a valid filespec ... |
64
|
0
|
|
|
|
|
|
$self->{'DOMAINNAME'} = $domainname; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $self->{'DOMAINNAME'}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub gettext { |
71
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
72
|
0
|
|
|
|
|
|
my ($msgid) = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Even more checking should be done here (and LC_CTYPE changed to LC_MESSAGES when Perl supports LC_MESSAGES) ... |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
0
|
|
|
|
if ((not defined $ENV{'NLSPATH'} or $ENV{'NLSPATH'} eq '') and |
|
|
|
0
|
|
|
|
|
77
|
|
|
|
|
|
|
(setlocale(LC_CTYPE) eq 'C')) { |
78
|
0
|
|
|
|
|
|
return $msgid; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $oldlocale = setlocale(LC_CTYPE); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return `LC_MESSAGES=$oldlocale;LANGUAGE=$oldlocale;TEXTDOMAINDIR=$self->{'DIRNAME'};$gettextcmd $self->{'DOMAINNAME'} $msgid`; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub dgettext { |
87
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
88
|
0
|
|
|
|
|
|
my ($domainname, $msgid) = @_; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Even more checking should be done here (and LC_CTYPE changed to LC_MESSAGES when Perl supports LC_MESSAGES) ... |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
0
|
|
|
|
if ((not defined $ENV{'NLSPATH'} or $ENV{'NLSPATH'} eq '') and |
|
|
|
0
|
|
|
|
|
93
|
|
|
|
|
|
|
(setlocale(LC_CTYPE) eq 'C')) { |
94
|
0
|
|
|
|
|
|
return $msgid; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $oldlocale = setlocale(LC_CTYPE); |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return `LC_MESSAGES=$oldlocale;LANGUAGE=$oldlocale;TEXTDOMAINDIR=$self->{'DIRNAME'};$gettextcmd $domainname $msgid`; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub dcgettext { |
103
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
104
|
0
|
|
|
|
|
|
my ($domainname, $msgid, $category) = @_; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Even more checking should be done here (and LC_CTYPE changed to LC_MESSAGES when Perl supports LC_MESSAGES) ... |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
0
|
|
|
|
if ((not defined $ENV{'NLSPATH'} or $ENV{'NLSPATH'} eq '') and |
|
|
|
0
|
|
|
|
|
109
|
|
|
|
|
|
|
(setlocale(LC_CTYPE) eq 'C')) { |
110
|
0
|
|
|
|
|
|
return $msgid; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# the env must be set, but this is kind of a shotgun approach ... |
114
|
0
|
|
|
|
|
|
return `LANGUAGE=$category;LC_MESSAGES=$category;TEXTDOMAINDIR=$self->{'DIRNAME'};$gettextcmd $domainname $msgid`; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub untaint { |
118
|
0
|
|
0
|
0
|
0
|
|
my $str = shift || ''; |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
return '' if $str eq ''; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$str =~ s/[^\w.\\\/-]//g; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return $str; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
__END__ |