]> granicus.if.org Git - php/commitdiff
add ngettext() support from Walter Franzini <walter@sys-net.it>, and use Z_*
authorChuck Hagenbuch <chagenbu@php.net>
Mon, 27 Aug 2001 18:43:07 +0000 (18:43 +0000)
committerChuck Hagenbuch <chagenbu@php.net>
Mon, 27 Aug 2001 18:43:07 +0000 (18:43 +0000)
macros.

ext/gettext/gettext.c
ext/gettext/php_gettext.h

index f5127b4baeda0ef90cf81e02d0ab226732304fc3..7c77480fad92e110a85d806d419ca3d08a200415 100644 (file)
@@ -40,6 +40,9 @@ function_entry php_gettext_functions[] = {
        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 @@ PHP_MINFO_FUNCTION(gettext)
    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 @@ PHP_FUNCTION(textdomain)
        }
        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 @@ PHP_FUNCTION(textdomain)
    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 @@ PHP_FUNCTION(gettext)
        }
        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 @@ PHP_FUNCTION(gettext)
    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 @@ PHP_FUNCTION(dgettext)
        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 @@ PHP_FUNCTION(dgettext)
    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 @@ PHP_FUNCTION(dcgettext)
        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 @@ PHP_FUNCTION(dcgettext)
    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,18 +160,107 @@ PHP_FUNCTION(bindtextdomain)
        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 c7323831ddab7e10b3ba1470bc243e5f452c7799..1cfa68f09c4ae20d82abadb27177f2e5d74762f4 100644 (file)
@@ -36,6 +36,9 @@ PHP_FUNCTION(gettext);
 PHP_FUNCTION(dgettext);
 PHP_FUNCTION(dcgettext);
 PHP_FUNCTION(bindtextdomain);
+PHP_FUNCTION(ngettext);
+PHP_FUNCTION(dngettext);
+PHP_FUNCTION(dcngettext);
 
 #else
 #define gettext_module_ptr NULL