我想在网站上使用gettext,为此我遵循O'Reilly Media tutorial。在第一页结尾处,它说我需要使用命令xgettext -n *.php
,但我的命令行返回以下内容:'xgettext' is not recognized as an internal or external command, operable program or batch file.
我在XAMPP上运行我的网站,因此我的整个目录是这样的: xampp/htdocs/gettext/locale/en/lc_messages/
PHP GetText命令不能在命令行工作
我有我的test.php在gettext文件夹和messages.po在en
文件夹中。即使我尝试使用poedit,它也不起作用。这里是我的test.php代码:
<?php
// I18N support information here
$language = 'en';
putenv("LANG=$language");
setlocale(LC_ALL, $language);
// Set the text domain as 'messages'
$domain = 'messages';
bindtextdomain($domain, "localhost/gettext/locale");
textdomain($domain);
echo "<br>";
echo gettext("A string to be translated would go here");
?>
我不太确定bindtextdomain函数中的字符串是否正确。有人有任何线索吗?
编辑:我忘记提及我在使用Windows。我已经检查过php目录,gettext扩展名在那里,它在php.ini配置文件中启用。
确保已安装它:'sudo apt-g和安装gettext'(如果运行灯设置) – MackieeE
我的坏,我忘了提及,我正在使用Windows。我已经检查过php目录,gettext扩展名在那里,它在php.ini配置文件中启用。 –
嗯,我应该注意到无论如何因为'XAMPP' :)看起来你可能需要一种不同的方法http://stackoverflow.com/a/10610166/292735 – MackieeE