php-src/ext/gettext/gettext.c

177 lines
4.8 KiB
C
Raw Normal View History

1999-04-22 01:26:16 +08:00
/*
+----------------------------------------------------------------------+
1999-07-16 21:13:16 +08:00
| PHP version 4.0 |
1999-04-22 01:26:16 +08:00
+----------------------------------------------------------------------+
2001-02-26 14:11:02 +08:00
| Copyright (c) 1997-2001 The PHP Group |
1999-04-22 01:26:16 +08:00
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
1999-07-16 21:13:16 +08:00
| 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. |
1999-07-16 21:13:16 +08:00
| 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. |
1999-04-22 01:26:16 +08:00
+----------------------------------------------------------------------+
| Author: Alex Plotnick <alex@wgate.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include <stdio.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
1999-04-22 01:26:16 +08:00
#include "php.h"
#include "php_gettext.h"
1999-04-22 01:26:16 +08:00
#if HAVE_LIBINTL
#include <libintl.h>
#include "ext/standard/info.h"
1999-04-22 01:26:16 +08:00
1999-12-18 05:50:07 +08:00
function_entry php_gettext_functions[] = {
2000-12-09 00:25:38 +08:00
PHP_FE(textdomain, NULL)
PHP_FE(gettext, NULL)
PHP_FALIAS(_, gettext, NULL)
PHP_FE(dgettext, NULL)
PHP_FE(dcgettext, NULL)
PHP_FE(bindtextdomain, NULL)
1999-04-22 01:26:16 +08:00
{NULL, NULL, NULL}
};
1999-12-18 05:50:07 +08:00
zend_module_entry php_gettext_module_entry = {
2000-12-10 23:53:37 +08:00
"gettext", php_gettext_functions, NULL, NULL, NULL, NULL, PHP_MINFO(gettext), STANDARD_MODULE_PROPERTIES
1999-04-22 01:26:16 +08:00
};
#ifdef COMPILE_DL_GETTEXT
ZEND_GET_MODULE(php_gettext)
#endif
1999-07-28 03:44:46 +08:00
PHP_MINFO_FUNCTION(gettext)
1999-04-22 01:26:16 +08:00
{
php_info_print_table_start();
php_info_print_table_row(2, "GNU GetText Support", "enabled");
php_info_print_table_end();
1999-04-22 01:26:16 +08:00
}
2000-03-20 07:39:05 +08:00
/* {{{ proto string textdomain(string domain)
2000-08-09 04:28:19 +08:00
Set the textdomain to "domain". Returns the current domain */
PHP_FUNCTION(textdomain)
1999-04-22 01:26:16 +08:00
{
2000-12-09 00:25:38 +08:00
pval **domain;
char *domain_name, *retval;
char *val;
1999-04-22 01:26:16 +08:00
2000-12-09 00:25:38 +08:00
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &domain) == FAILURE) {
1999-04-22 01:26:16 +08:00
WRONG_PARAM_COUNT;
2000-12-09 00:25:38 +08:00
}
convert_to_string_ex(domain);
1999-04-22 01:26:16 +08:00
val = (*domain)->value.str.val;
if (strcmp(val, "") && strcmp(val, "0")) {
domain_name = val;
1999-04-22 01:26:16 +08:00
} else {
domain_name = NULL;
}
retval = textdomain(domain_name);
2000-12-09 00:25:38 +08:00
RETURN_STRING(retval, 1);
1999-04-22 01:26:16 +08:00
}
2000-03-20 07:39:05 +08:00
/* }}} */
1999-04-22 01:26:16 +08:00
2000-03-20 07:39:05 +08:00
/* {{{ proto string gettext(string msgid)
2000-08-09 04:28:19 +08:00
Return the translation of msgid for the current domain, or msgid unaltered if a translation does not exist */
PHP_FUNCTION(gettext)
1999-04-22 01:26:16 +08:00
{
2000-12-09 00:25:38 +08:00
pval **msgid;
char *msgstr;
1999-04-22 01:26:16 +08:00
2000-12-09 00:25:38 +08:00
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &msgid) == FAILURE) {
1999-04-22 01:26:16 +08:00
WRONG_PARAM_COUNT;
2000-12-09 00:25:38 +08:00
}
convert_to_string_ex(msgid);
1999-04-22 01:26:16 +08:00
2000-12-09 00:25:38 +08:00
msgstr = gettext((*msgid)->value.str.val);
1999-04-22 01:26:16 +08:00
2000-12-09 00:25:38 +08:00
RETURN_STRING(msgstr, 1);
1999-04-22 01:26:16 +08:00
}
2000-03-20 07:39:05 +08:00
/* }}} */
1999-04-22 01:26:16 +08:00
2000-03-20 07:39:05 +08:00
/* {{{ proto string dgettext(string domain_name, string msgid)
2000-08-09 04:28:19 +08:00
Return the translation of msgid for domain_name, or msgid unaltered if a translation does not exist */
PHP_FUNCTION(dgettext)
1999-04-22 01:26:16 +08:00
{
pval **domain_name, **msgid;
1999-04-22 01:26:16 +08:00
char *msgstr;
2000-12-09 00:25:38 +08:00
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &domain_name, &msgid) == FAILURE) {
1999-04-22 01:26:16 +08:00
WRONG_PARAM_COUNT;
}
convert_to_string_ex(domain_name);
convert_to_string_ex(msgid);
1999-04-22 01:26:16 +08:00
msgstr = dgettext((*domain_name)->value.str.val, (*msgid)->value.str.val);
1999-04-22 01:26:16 +08:00
RETURN_STRING(msgstr, 1);
}
2000-03-20 07:39:05 +08:00
/* }}} */
1999-04-22 01:26:16 +08:00
2000-03-20 07:39:05 +08:00
/* {{{ proto string dcgettext(string domain_name, string msgid, long category)
2000-08-09 04:28:19 +08:00
Return the translation of msgid for domain_name and category, or msgid unaltered if a translation does not exist */
PHP_FUNCTION(dcgettext)
1999-04-22 01:26:16 +08:00
{
pval **domain_name, **msgid, **category;
1999-04-22 01:26:16 +08:00
char *msgstr;
2000-12-09 00:25:38 +08:00
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &domain_name, &msgid, &category) == FAILURE) {
1999-04-22 01:26:16 +08:00
WRONG_PARAM_COUNT;
}
convert_to_string_ex(domain_name);
convert_to_string_ex(msgid);
convert_to_long_ex(category);
1999-04-22 01:26:16 +08:00
2000-12-09 00:25:38 +08:00
msgstr = dcgettext( (*domain_name)->value.str.val,
(*msgid)->value.str.val,
(*category)->value.lval);
1999-04-22 01:26:16 +08:00
RETURN_STRING(msgstr, 1);
}
2000-03-20 07:39:05 +08:00
/* }}} */
1999-04-22 01:26:16 +08:00
2000-03-20 07:39:05 +08:00
/* {{{ proto string bindtextdomain(string domain_name, string dir)
2000-08-09 04:28:19 +08:00
Bind to the text domain domain_name, looking for translations in dir. Returns the current domain */
PHP_FUNCTION(bindtextdomain)
1999-04-22 01:26:16 +08:00
{
pval **domain_name, **dir;
2000-11-28 02:21:48 +08:00
char *retval, dir_name[MAXPATHLEN];
1999-04-22 01:26:16 +08:00
2000-12-09 00:25:38 +08:00
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &domain_name, &dir) == FAILURE) {
1999-04-22 01:26:16 +08:00
WRONG_PARAM_COUNT;
}
convert_to_string_ex(domain_name);
convert_to_string_ex(dir);
1999-04-22 01:26:16 +08:00
2000-11-28 02:21:48 +08:00
if (strcmp((*dir)->value.str.val, "") && strcmp((*dir)->value.str.val, "0")) {
VCWD_REALPATH((*dir)->value.str.val, dir_name);
1999-04-22 01:26:16 +08:00
} else {
VCWD_GETCWD(dir_name, MAXPATHLEN);
1999-04-22 01:26:16 +08:00
}
retval = bindtextdomain((*domain_name)->value.str.val, dir_name);
1999-04-22 01:26:16 +08:00
RETURN_STRING(retval, 1);
}
2000-03-20 07:39:05 +08:00
/* }}} */
1999-04-22 01:26:16 +08:00
#endif /* HAVE_LIBINTL */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/