Php gettext在一个文件中工作,而不是在另一个文件中工作?

Php gettext在一个文件中工作,而不是在另一个文件中工作?,php,class,function,translation,gettext,Php,Class,Function,Translation,Gettext,让gettext开始工作我有点困难。我制作了一个简单的测试文件,在其中我调用translate.php和echo T_uux(“XXXXX”)并对其进行翻译,但是当我尝试在函数中使用echo T_uu时,它不起作用 translate.php: <?php error_reporting(E_ALL | E_STRICT); // define constants define('PROJECT_DIR', realpath('./functions/')); //define

让gettext开始工作我有点困难。我制作了一个简单的测试文件,在其中我调用translate.php和echo T_uux(“XXXXX”)并对其进行翻译,但是当我尝试在函数中使用echo T_uu时,它不起作用

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");
?>

工作测试文件:

<?php
require("translate.php"); 

echo T_("test"); 

?>

这只是一个测试,看看它是否有效,“测试”一词被翻译成我希望达到的效果。实际的php文件会变得更复杂一些

info.php

<?php

    require("functions\info_functions.php");

    (...)

    class infopage extends Page
    {
        public function display()
        {
        (...)

        displayInfo();

        (...)
        }
    }   


    $homepage = new infopage(); 
    $homepage->display();   

?>

info_functions.php-这里的回声不会被翻译

<?php

require("translate.php"); 

echo T_("test"); 

            function displayInfo()
            {

            (...)

            echo T_("test"); 

            (...)

            }

?>  

检查您的
LOCALE\u DIR
环境变量是否实际指向
displayInfo()中的正确位置。发件人:

// define constants
define('PROJECT_DIR', realpath('./functions/'));
//define('LOCALE_DIR', PROJECT_DIR .'/functions/locale');
define('LOCALE_DIR', PROJECT_DIR .'locale');
它看起来可能是一个相对路径,在
info\u functions.php
中不起作用,因为它与其他(测试)文件位于不同的目录中