[英]I18n using PHP gettext()
我正在尝试使用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,*。em文件。
以上代码摘自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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.