【发布时间】:2017-09-07 13:25:33
【问题描述】:
我正在尝试使用我已实现以下代码的 PHP gettext() 翻译我的网站:
if ( false === function_exists('gettext') ) {
echo "You do not have the gettext library installed with PHP.";
exit(1);
}
setlocale(LC_ALL, 'en_US.UTF-8');
$localedir = dirname(__FILE__) . '/Locale';
echo $localedir . ': ';
bindtextdomain('messages', $localedir);
textdomain('messages');
echo gettext("Hello");
exit(0);
但它似乎不起作用,因为它正在回显我在 gettext() 中传递的相同字符串。
我按照 https://blog.udemy.com/php-gettext/ 教程使用 poedit 创建了 *.po、*.mo 文件。
以上代码取自https://github.com/nota-ja/php-gettext-example/blob/master/index.php
但是,虽然有这样的解决方案,但我无法翻译给定的内容。任何形式的帮助将不胜感激。
谢谢!
【问题讨论】:
-
gettext 应该是这样的 gettext(){}
-
而且你不必检查 false function_exists 将检查函数是否存在
-
@Anil Shrestha gettext(){} 给出语法错误。请详细说明我应该传递给 gettext 函数的内容。此外,加载翻译文件似乎存在路径问题。
标签: php internationalization translation gettext