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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
/*
+----------------------------------------------------------------------+
| PHP Version 4 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2002 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_02.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Alex Plotnick <alex@wgate.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include <stdio.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_gettext.h"
#if HAVE_LIBINTL
#include <libintl.h>
#include "ext/standard/info.h"
/* {{{ php_gettext_functions[]
*/
function_entry php_gettext_functions[] = {
PHP_FE(textdomain, NULL)
PHP_FE(gettext, NULL)
PHP_FALIAS(_, gettext, NULL)
PHP_FE(dgettext, NULL)
PHP_FE(dcgettext, NULL)
PHP_FE(bindtextdomain, NULL)
#if HAVE_NGETTEXT
PHP_FE(ngettext, NULL)
#endif
#if HAVE_DNGETTEXT
PHP_FE(dngettext, NULL)
#endif
#if HAVE_DCNGETTEXT
PHP_FE(dcngettext, NULL)
#endif
#if HAVE_BIND_TEXTDOMAIN_CODESET
PHP_FE(bind_textdomain_codeset, NULL)
#endif
{NULL, NULL, NULL}
};
/* }}} */
zend_module_entry php_gettext_module_entry = {
STANDARD_MODULE_HEADER,
"gettext",
php_gettext_functions,
NULL,
NULL,
NULL,
NULL,
PHP_MINFO(gettext),
NO_VERSION_YET,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_GETTEXT
ZEND_GET_MODULE(php_gettext)
#endif
PHP_MINFO_FUNCTION(gettext)
{
php_info_print_table_start();
php_info_print_table_row(2, "GetText Support", "enabled");
php_info_print_table_end();
}
/* {{{ proto string textdomain(string domain)
Set the textdomain to "domain". Returns the current domain */
PHP_FUNCTION(textdomain)
{
zval **domain;
char *domain_name, *retval;
char *val;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &domain) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(domain);
val = Z_STRVAL_PP(domain);
if (strcmp(val, "") && strcmp(val, "0")) {
domain_name = val;
} else {
domain_name = NULL;
}
retval = textdomain(domain_name);
RETURN_STRING(retval, 1);
}
/* }}} */
/* {{{ proto string gettext(string msgid)
Return the translation of msgid for the current domain, or msgid unaltered if a translation does not exist */
PHP_FUNCTION(gettext)
{
zval **msgid;
char *msgstr;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &msgid) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(msgid);
msgstr = gettext(Z_STRVAL_PP(msgid));
RETURN_STRING(msgstr, 1);
}
/* }}} */
/* {{{ proto string dgettext(string domain_name, string msgid)
Return the translation of msgid for domain_name, or msgid unaltered if a translation does not exist */
PHP_FUNCTION(dgettext)
{
zval **domain_name, **msgid;
char *msgstr;
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &domain_name, &msgid) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(domain_name);
convert_to_string_ex(msgid);
msgstr = dgettext(Z_STRVAL_PP(domain_name), Z_STRVAL_PP(msgid));
RETURN_STRING(msgstr, 1);
}
/* }}} */
/* {{{ proto string dcgettext(string domain_name, string msgid, long category)
Return the translation of msgid for domain_name and category, or msgid unaltered if a translation does not exist */
PHP_FUNCTION(dcgettext)
{
zval **domain_name, **msgid, **category;
char *msgstr;
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &domain_name, &msgid, &category) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(domain_name);
convert_to_string_ex(msgid);
convert_to_long_ex(category);
msgstr = dcgettext(Z_STRVAL_PP(domain_name), Z_STRVAL_PP(msgid), Z_LVAL_PP(category));
RETURN_STRING(msgstr, 1);
}
/* }}} */
/* {{{ proto string bindtextdomain(string domain_name, string dir)
Bind to the text domain domain_name, looking for translations in dir. Returns the current domain */
PHP_FUNCTION(bindtextdomain)
{
zval **domain_name, **dir;
char *retval, dir_name[MAXPATHLEN];
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &domain_name, &dir) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(domain_name);
convert_to_string_ex(dir);
if (strcmp(Z_STRVAL_PP(dir), "") && strcmp(Z_STRVAL_PP(dir), "0")) {
VCWD_REALPATH(Z_STRVAL_PP(dir), dir_name);
} else {
VCWD_GETCWD(dir_name, MAXPATHLEN);
}
retval = bindtextdomain(Z_STRVAL_PP(domain_name), dir_name);
RETURN_STRING(retval, 1);
}
/* }}} */
#if HAVE_NGETTEXT
/* {{{ proto string ngettext(string MSGID1, string MSGID2, int N)
Plural version of gettext() */
PHP_FUNCTION(ngettext)
{
zval **msgid1, **msgid2, **count;
char *msgstr;
RETVAL_FALSE;
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &msgid1, &msgid2, &count) == FAILURE) {
WRONG_PARAM_COUNT;
} else {
convert_to_string_ex(msgid1);
convert_to_string_ex(msgid2);
convert_to_long_ex(count);
msgstr = ngettext(Z_STRVAL_PP(msgid1), Z_STRVAL_PP(msgid2), Z_LVAL_PP(count));
if (msgstr) {
RETVAL_STRING (msgstr, 1);
}
}
}
/* }}} */
#endif
#if HAVE_DNGETTEXT
/* {{{ proto string dngettext (string domain, string msgid1, string msgid2, int count)
Plural version of dgettext() */
PHP_FUNCTION(dngettext)
{
zval **domain, **msgid1, **msgid2, **count;
RETVAL_FALSE;
if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &domain, &msgid1, &msgid2, &count) == FAILURE) {
WRONG_PARAM_COUNT;
} else {
char *msgstr;
convert_to_string_ex(domain);
convert_to_string_ex(msgid1);
convert_to_string_ex(msgid2);
convert_to_long_ex(count);
msgstr = dngettext(Z_STRVAL_PP(domain), Z_STRVAL_PP(msgid1), Z_STRVAL_PP(msgid2), Z_LVAL_PP(count));
if (msgstr) {
RETVAL_STRING(msgstr, 1);
}
}
}
/* }}} */
#endif
#if HAVE_DCNGETTEXT
/* {{{ proto string dcngettext (string domain, string msgid1, string msgid2, int n, int category)
Plural version of dcgettext() */
PHP_FUNCTION(dcngettext)
{
zval **domain, **msgid1, **msgid2, **count, **category;
RETVAL_FALSE;
if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(4, &domain, &msgid1, &msgid2, &count, &category) == FAILURE) {
WRONG_PARAM_COUNT;
} else {
char* msgstr = NULL;
convert_to_string_ex(domain);
convert_to_string_ex(msgid1);
convert_to_string_ex(msgid2);
convert_to_long_ex(count);
convert_to_long_ex(category);
msgstr = dcngettext(Z_STRVAL_PP(domain), Z_STRVAL_PP(msgid1), Z_STRVAL_PP(msgid2), Z_LVAL_PP(count), Z_LVAL_PP(category));
if (msgstr) {
RETVAL_STRING(msgstr, 1);
}
}
}
/* }}} */
#endif
#if HAVE_BIND_TEXTDOMAIN_CODESET
/* {{{ proto string bind_textdomain_codeset (string domain, string codeset)
Specify the character encoding in which the messages from the DOMAIN message catalog will be returned. */
PHP_FUNCTION(bind_textdomain_codeset)
{
zval **domain, **codeset;
char *retval;
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &domain, &codeset) == FAILURE) {
WRONG_PARAM_COUNT;
} else {
convert_to_string_ex(domain);
convert_to_string_ex(codeset);
retval = bind_textdomain_codeset(Z_STRVAL_PP(domain), Z_STRVAL_PP(codeset));
if (!retval) {
RETURN_FALSE;
}
RETURN_STRING(retval, 1);
}
}
/* }}} */
#endif
#endif /* HAVE_LIBINTL */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/
|