使用poedit和.po文件的创建,一切正常。 问题是我的PHP文件一直向我发送消息错误:
致命错误:无法在第12行的C:\ xampp \ htdocs \ gettextdemo \ demo.php中重新声明_()
这是php文件的代码
<?php /* Date de création: 2014-03-16 */ ?>
<html>
<body>
<?php
require_once("lib/streams.php");
require_once("lib/gettext.php");
$locle_lang = $_GET['lang'];
$locale_file = new FileReader("locale/$locle_lang/LC_MESSAGES/messages.mo");
$locale_fetch = new gettext_reader($locale_file);
function _($text)
{
global $locale_fetch;
return $locale_fetch->translate($text);
}
?>
<h1><?php echo _("The best place in the world to get some text") ?> </h1> <p>
<?php echo _("the greatest son fo the bayou") ?> </p>
</body>
</html>
抱歉,我无法弄清楚错误
谢谢
答案 0 :(得分:0)
函数 _ 是gettext的保留函数。重命名吧! 例如:
<?php /* Date de création: 2014-03-16 */ ?>
<html>
<body>
<?php
require_once("lib/streams.php");
require_once("lib/gettext.php");
$locle_lang = $_GET['lang'];
$locale_file = new FileReader("locale/$locle_lang/LC_MESSAGES/messages.mo");
$locale_fetch = new gettext_reader($locale_file);
function __($text) {
global $locale_fetch;
return $locale_fetch->translate($text);
}
?>
<h1><?php echo __("The best place in the world to get some text") ?> </h1> <p>
<?php echo __("the greatest son fo the bayou") ?> </p>
</body>
</html>