我正在尝试使用 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
但是虽然有这样的解决方案,但我无法翻译给定的内容。我们将不胜感激。
谢谢!
最佳答案
您不必使用 function_exists 等于 false。 function_exists 将检查函数是否存在
if (function_exists('gettext')) {
// this function exists
}else{
echo "You do not have the gettext library installed with PHP.";
exit(1);
}
关于php - I18n 使用 PHP gettext(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46097610/