cvs: php4 /ext/gettext gettext.c php_gettext.h
| From: | Chuck Hagenbuch | Date: | Mon, 27 Aug 2001 18:43:08 +0000 |
| Subject: | cvs: php4 /ext/gettext gettext.c php_gettext.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-7098@lists.php.net to get a copy of this message | ||
chagenbu Mon Aug 27 14:43:08 2001 EDT
Modified files:
/php4/ext/gettext gettext.c php_gettext.h
Log:
add ngettext() support from Walter Franzini <walter@sys-net.it>, and use Z_*
macros.
Index: php4/ext/gettext/gettext.c
diff -u php4/ext/gettext/gettext.c:1.29 php4/ext/gettext/gettext.c:1.30
--- php4/ext/gettext/gettext.c:1.29 Sat Jun 9 12:55:27 2001
+++ php4/ext/gettext/gettext.c Mon Aug 27 14:43:07 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: gettext.c,v 1.29 2001/06/09 16:55:27 sas Exp $ */
+/* $Id: gettext.c,v 1.30 2001/08/27 18:43:07 chagenbu Exp $ */
#include <stdio.h>
#ifdef HAVE_CONFIG_H
@@ -40,6 +40,9 @@
PHP_FE(dgettext, NULL)
PHP_FE(dcgettext, NULL)
PHP_FE(bindtextdomain, NULL)
+ PHP_FE(ngettext, NULL)
+ PHP_FE(dngettext, NULL)
+ PHP_FE(dcngettext, NULL)
{NULL, NULL, NULL}
};
/* }}} */
@@ -63,7 +66,7 @@
Set the textdomain to "domain". Returns the current domain */
PHP_FUNCTION(textdomain)
{
- pval **domain;
+ zval **domain;
char *domain_name, *retval;
char *val;
@@ -72,7 +75,7 @@
}
convert_to_string_ex(domain);
- val = (*domain)->value.str.val;
+ val = Z_STRVAL_PP(domain);
if (strcmp(val, "") && strcmp(val, "0")) {
domain_name = val;
} else {
@@ -89,7 +92,7 @@
Return the translation of msgid for the current domain, or msgid unaltered if a translation does
not exist */
PHP_FUNCTION(gettext)
{
- pval **msgid;
+ zval **msgid;
char *msgstr;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &msgid) == FAILURE) {
@@ -97,7 +100,7 @@
}
convert_to_string_ex(msgid);
- msgstr = gettext((*msgid)->value.str.val);
+ msgstr = gettext(Z_STRVAL_PP(msgid));
RETURN_STRING(msgstr, 1);
}
@@ -107,7 +110,7 @@
Return the translation of msgid for domain_name, or msgid unaltered if a translation does not
exist */
PHP_FUNCTION(dgettext)
{
- pval **domain_name, **msgid;
+ zval **domain_name, **msgid;
char *msgstr;
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &domain_name, &msgid) == FAILURE) {
@@ -116,7 +119,7 @@
convert_to_string_ex(domain_name);
convert_to_string_ex(msgid);
- msgstr = dgettext((*domain_name)->value.str.val, (*msgid)->value.str.val);
+ msgstr = dgettext(Z_STRVAL_PP(domain_name), Z_STRVAL_PP(msgid));
RETURN_STRING(msgstr, 1);
}
@@ -126,7 +129,7 @@
Return the translation of msgid for domain_name and category, or msgid unaltered if a
translation does not exist */
PHP_FUNCTION(dcgettext)
{
- pval **domain_name, **msgid, **category;
+ zval **domain_name, **msgid, **category;
char *msgstr;
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &domain_name, &msgid, &category)
== FAILURE) {
@@ -136,9 +139,9 @@
convert_to_string_ex(msgid);
convert_to_long_ex(category);
- msgstr = dcgettext( (*domain_name)->value.str.val,
- (*msgid)->value.str.val,
- (*category)->value.lval);
+ msgstr = dcgettext(Z_STRVAL_PP(domain_name),
+ Z_STRVAL_PP(msgid),
+ Z_LVAL_PP(category));
RETURN_STRING(msgstr, 1);
}
@@ -148,7 +151,7 @@
Bind to the text domain domain_name, looking for translations in dir. Returns the current domain
*/
PHP_FUNCTION(bindtextdomain)
{
- pval **domain_name, **dir;
+ zval **domain_name, **dir;
char *retval, dir_name[MAXPATHLEN];
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &domain_name, &dir) == FAILURE) {
@@ -157,17 +160,106 @@
convert_to_string_ex(domain_name);
convert_to_string_ex(dir);
- if (strcmp((*dir)->value.str.val, "") && strcmp((*dir)->value.str.val,
"0")) {
- VCWD_REALPATH((*dir)->value.str.val, dir_name);
+ 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((*domain_name)->value.str.val, dir_name);
+ retval = bindtextdomain(Z_STRVAL_PP(domain_name), dir_name);
RETURN_STRING(retval, 1);
}
/* }}} */
+
+/* {{{ proto string ngettext(string MSGID1, string MSGID2, int N)
+ The
ngettext' function is similar to the gettext' function as it finds
the message catalogs in the same way. But it takes two extra arguments. The MSGID1 parameter must
contain the singular form of the string to be converted. It is also used as the key for the search
in the catalog. The MSGID2 parameter is the plural form. The parameter N is used to determine the
plural form. If no message catalog is found MSGID1 is returned if n == 1', otherwise
msgid2'.
+*/
+PHP_FUNCTION(ngettext)
+{
+ zval **msgid1, **msgid2, **count;
+ char *msgstr;
+
+ RETVAL_FALSE;
+
+ if (3 != ZEND_NUM_ARGS()
+ || FAILURE == zend_get_parameters_ex(3, &msgid1, &msgid2, &count)) {
+ 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);
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto string dngettext (string domain, string msgid1, string msgid2, long count)
+ The dngettext' is similar to the dgettext' function in the way the
message catalog is selected. The difference is that it takes two extra parameter to provide the
correct plural form. These two parameters are handled in the same way `ngettext' handles them.
+ */
+PHP_FUNCTION(dngettext)
+{
+ zval **domain, **msgid1, **msgid2, **count;
+
+ RETVAL_FALSE;
+
+ if (4 != ZEND_NUM_ARGS()
+ || FAILURE == zend_get_parameters_ex(4, &domain, &msgid1, &msgid2,
+ &count)) {
+ 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);
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto string dcngettext (string domain, string msgid1, string msgid2, long n, int category)
+ The dcngettext' is similar to the dcgettext' function in the way the
message catalog is selected. The difference is that it takes two extra parameter to provide the
correct plural form. These two parameters are handled in the same way `ngettext' handles them.
+*/
+PHP_FUNCTION(dcngettext)
+{
+ zval **domain, **msgid1, **msgid2, **count, **category;
+
+ RETVAL_FALSE;
+
+ if (5 != ZEND_NUM_ARGS()
+ || FAILURE == zend_get_parameters_ex(4, &domain, &msgid1, &msgid2,
+ &count, &category)) {
+
+ } 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 /* HAVE_LIBINTL */
Index: php4/ext/gettext/php_gettext.h
diff -u php4/ext/gettext/php_gettext.h:1.11 php4/ext/gettext/php_gettext.h:1.12
--- php4/ext/gettext/php_gettext.h:1.11 Mon Feb 26 13:14:28 2001
+++ php4/ext/gettext/php_gettext.h Mon Aug 27 14:43:07 2001
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_gettext.h,v 1.11 2001/02/26 18:14:28 andi Exp $ */
+/* $Id: php_gettext.h,v 1.12 2001/08/27 18:43:07 chagenbu Exp $ */
#ifndef PHP_GETTEXT_H
#define PHP_GETTEXT_H
@@ -36,6 +36,9 @@
PHP_FUNCTION(dgettext);
PHP_FUNCTION(dcgettext);
PHP_FUNCTION(bindtextdomain);
+PHP_FUNCTION(ngettext);
+PHP_FUNCTION(dngettext);
+PHP_FUNCTION(dcngettext);
#else
#define gettext_module_ptr NULL