Hi all,

I have added to ext/gettext the wrapper needed to support *ngettext
functions, you can find the patch below.

Ciao
-- 
Walter Franzini, e-mail: [EMAIL PROTECTED]
SysNet, Via Digione 8, 27100 Pavia - Italy

diff -aur php-4.0.6.ORIG/ext/gettext/gettext.c 
php-4.0.6+gettext-patch/ext/gettext/gettext.c
--- php-4.0.6.ORIG/ext/gettext/gettext.c        Thu May 24 14:41:51 2001
+++ php-4.0.6+gettext-patch/ext/gettext/gettext.c       Sun Aug 26 18:13:42 2001
@@ -38,6 +38,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}
 };
 
@@ -165,6 +168,97 @@
        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)
+{
+    pval **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 ((*msgid1)->value.str.val, (*msgid2)->value.str.val,
+                           (*count)->value.lval);
+        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)
+{
+    pval **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 ((*domain)->value.str.val, (*msgid1)->value.str.val,
+                            (*msgid2)->value.str.val, (*count)->value.lval);
+        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)
+{
+    pval **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 ((*domain)->value.str.val, (*msgid1)->value.str.val,
+                             (*msgid2)->value.str.val, (*count)->value.lval,
+                             (*category)->value.lval);
+
+        if (msgstr) {
+            RETVAL_STRING (msgstr, 1);
+        }
+    }
+}
 
 #endif /* HAVE_LIBINTL */
 
Only in php-4.0.6+gettext-patch/ext/gettext/: libs.mk
diff -aur php-4.0.6.ORIG/ext/gettext/php_gettext.h 
php-4.0.6+gettext-patch/ext/gettext/php_gettext.h
--- php-4.0.6.ORIG/ext/gettext/php_gettext.h    Mon Feb 26 19:14:28 2001
+++ php-4.0.6+gettext-patch/ext/gettext/php_gettext.h   Sun Aug 26 17:16:32 2001
@@ -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
Only in php-4.0.6+gettext-patch/ext/gettext/: tests


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to