1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
#! /bin/false
# vim: tabstop=4
# $Id: gettext_xs.pm,v 1.1 2011-10-12 23:51:26 pertusus Exp $
# Pure Perl implementation of Uniforum message translation.
# Copyright (C) 2002-2009 Guido Flohr <guido@imperia.net>,
# all rights reserved.
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
package Locale::gettext_xs;
require DynaLoader;
require Exporter;
use vars qw (%EXPORT_TAGS @EXPORT_OK @ISA);
%EXPORT_TAGS = (locale_h => [ qw (
gettext
dgettext
dcgettext
ngettext
dngettext
dcngettext
pgettext
dpgettext
dcpgettext
npgettext
dnpgettext
dcnpgettext
textdomain
bindtextdomain
bind_textdomain_codeset
)
],
libintl_h => [ qw (LC_CTYPE
LC_NUMERIC
LC_TIME
LC_COLLATE
LC_MONETARY
LC_MESSAGES
LC_ALL)
],
);
@EXPORT_OK = qw (gettext
dgettext
dcgettext
ngettext
dngettext
dcngettext
pgettext
dpgettext
dcpgettext
npgettext
dnpgettext
dcnpgettext
textdomain
bindtextdomain
bind_textdomain_codeset
nl_putenv
LC_CTYPE
LC_NUMERIC
LC_TIME
LC_COLLATE
LC_MONETARY
LC_MESSAGES
LC_ALL);
@ISA = qw (Exporter DynaLoader);
bootstrap Locale::gettext_xs;
require File::Spec;
# Reimplement pgettext functions
sub pgettext ($$) {
my ($msgctxt, $msgid) = @_;
my $msg_ctxt_id = join("\004", $msgctxt, $msgid);
return Locale::gettext_xs::_pgettext_aux
("", $msg_ctxt_id, $msgid, Locale::gettext_xs::LC_MESSAGES());
}
sub dpgettext ($$$) {
my ($domain, $msgctxt, $msgid) = @_;
my $msg_ctxt_id = join("\004", $msgctxt, $msgid);
return Locale::gettext_xs::_pgettext_aux
($domain, $msg_ctxt_id, $msgid, Locale::gettext_xs::LC_MESSAGES());
}
sub dcpgettext ($$$$) {
my ($domain, $msgctxt, $msgid, $category) = @_;
my $msg_ctxt_id = join("\004", $msgctxt, $msgid);
return Locale::gettext_xs::_pgettext_aux
($domain, $msg_ctxt_id, $msgid, $category);
}
# Reimplement npgettext functions
sub npgettext ($$$$) {
my ($msgctxt, $msgid1, $msgid2, $n) = @_;
my $msg_ctxt_id = join("\004", $msgctxt, $msgid1);
return Locale::gettext_xs::_npgettext_aux
("", $msg_ctxt_id, $msgid1, $msgid2, $n, Locale::gettext_xs::LC_MESSAGES());
}
sub dnpgettext ($$$$$) {
my ($domain, $msgctxt, $msgid1, $msgid2, $n) = @_;
my $msg_ctxt_id = join("\004", $msgctxt, $msgid1);
return Locale::gettext_xs::_npgettext_aux
($domain, $msg_ctxt_id, $msgid1, $msgid2, $n, Locale::gettext_xs::LC_MESSAGES());
}
sub dcnpgettext ($$$$$$) {
my ($domain, $msgctxt, $msgid1, $msgid2, $n, $category) = @_;
my $msg_ctxt_id = join("\004", $msgctxt, $msgid1);
return Locale::gettext_xs::_npgettext_aux
($domain, $msg_ctxt_id, $msgid1, $msgid2, $n, $category);
}
# Wrapper function that converts Perl paths to OS paths.
sub bindtextdomain ($;$) {
my ($domain, $directory) = @_;
if (defined $domain && length $domain &&
defined $directory && length $directory) {
return Locale::gettext_xs::_bindtextdomain
($domain, File::Spec->catdir ($directory));
} else {
return &Locale::gettext_xs::_bindtextdomain;
}
}
# In the XS version, making the prototype optional, does not work.
sub textdomain (;$) {
my $domain = shift;
if (defined $domain) {
return Locale::gettext_xs::_textdomain ($domain);
} else {
return Locale::gettext_xs::_textdomain ("");
}
}
sub nl_putenv ($) {
my ($envspec) = @_;
return unless defined $envspec;
return unless length $envspec;
return if substr ($envspec, 0, 1) eq '=';
my ($var, $value) = split /=/, $envspec, 2;
if ($^O eq 'MSWin32') {
$value = '' unless defined $value;
return unless Locale::gettext_xs::_nl_putenv ("$var=$value") == 0;
if (length $value) {
$ENV{$var} = $value;
} else {
delete $ENV{$var};
}
} else {
if (defined $value) {
$ENV{$var} = $value;
} else {
delete $ENV{$var};
}
}
return 1;
}
1;
__END__
Local Variables:
mode: perl
perl-indent-level: 4
perl-continued-statement-offset: 4
perl-continued-brace-offset: 0
perl-brace-offset: -4
perl-brace-imaginary-offset: 0
perl-label-offset: -4
tab-width: 4
End:
|