php + gettext
I'm trying to get a php script to work with gettext for translations but it doesn't seem to be working. I have gettext installed on the local system. php is compiled with gettext support. Safe mode is set to off in php.ini. Here is the php file:
Code:
<?php
$language = ( isset($HTTP_GET_VARS['language']) ) ? $HTTP_GET_VARS['language'] : 'en_US';
putenv("LC_ALL=$language");
setlocale(LC_ALL, $language);
$domain = 'messages';
bindtextdomain($domain, "./locale");
textdomain($domain);
bind_textdomain_codeset($domain, 'ISO-8859-1');
header("Content-Type: text/html; charset=ISO-8859-1");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>i18n test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><!-- more ISO-8859-1 -->
</head>
<body>
<?=sprintf(gettext("Your browser says you prefer the %s language."), $_SERVER["HTTP_ACCEPT_LANGUAGE"])?><br />
<?=gettext("This is a test.")?>
<br />
<a href="index.php?language=en_US"><?=gettext("English")?></a><br />
<a href="index.php?language=es_US"><?=gettext("Spanish")?></a>
</body>
</html>
I have created the 2 required files, per locale (*.po & *.mo) and placed them in /root/directory/to/web/locale/$language/LC_MESSAGES
It always displays in english. Is the script bad? Am I missing some parameter somewhere?
Thanks
|