Hi. I have a little trouble getting gettext to work. I made a simple test file where I call the translate.php and echo T_("XXXXX") and It get translated, but when I try to use echo T_ in a function it doesn't work..
translate.php:
<?php
error_reporting(E_ALL | E_STRICT);
// define constants
define('PROJECT_DIR', realpath('./functions/'));
//define('LOCALE_DIR', PROJECT_DIR .'/functions/locale');
define('LOCALE_DIR', PROJECT_DIR .'locale');
define('DEFAULT_LOCALE', 'en_US');
require_once('gettext.inc');
$supported_locales = array('en_US', 'sr_CS', 'de_CH');
$encoding = 'UTF-8';
$locale = (isset($_GET['lang']))? $_GET['lang'] : DEFAULT_LOCALE;
// gettext setup
T_setlocale(LC_MESSAGES, $locale);
// Set the text domain as 'messages'
$domain = 'messages';
T_bindtextdomain($domain, LOCALE_DIR);
T_bind_textdomain_codeset($domain, $encoding);
T_textdomain($domain);
//header("Content-type: text/html; charset=$encoding");
?>
working test file:
<?php
require("translate.php");
echo T_("test");
?>
That was just a test to see if it worked and the "test" word got translated as I was hoping to achieve. It gets a little bit more complicated with actual php files.
info.php
<?php
require("functions\info_functions.php");
(...)
class infopage extends Page
{
public function display()
{
(...)
displayInfo();
(...)
}
}
$homepage = new infopage();
$homepage->display();
?>
info_functions.php - Here the echo doesn't get translated!
<?php
require("translate.php");
echo T_("test");
function displayInfo()
{
(...)
echo T_("test");
(...)
}
?>