php-src/ext/gettext/gettext.c

192 lines
5.5 KiB
C
Raw Normal View History

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