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}
};
/* }}} */
Set the textdomain to "domain". Returns the current domain */
PHP_FUNCTION(textdomain)
{
- pval **domain;
+ zval **domain;
char *domain_name, *retval;
char *val;
}
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 {
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) {
}
convert_to_string_ex(msgid);
- msgstr = gettext((*msgid)->value.str.val);
+ msgstr = gettext(Z_STRVAL_PP(msgid));
RETURN_STRING(msgstr, 1);
}
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) {
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);
}
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) {
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);
}
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) {
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 */
/*