[英]I18n using PHP gettext()
I am trying to translate my website using PHP gettext() for which I have implemented the following code: 我正在尝试使用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);
But it doesnot seem to work because it is echoing the same string what I pass in gettext(). 但它似乎没有用,因为它回显了我在gettext()中传递的相同字符串。
I have created the *.po, *.mo files using poedit while following https://blog.udemy.com/php-gettext/ tutorial. 我在关注https://blog.udemy.com/php-gettext/教程时使用poedit创建了* .po,*。em文件。
The above code has been taken from https://github.com/nota-ja/php-gettext-example/blob/master/index.php 以上代码摘自https://github.com/nota-ja/php-gettext-example/blob/master/index.php
But while having such solutions I am unable to translate the given content. 但是,虽然有这样的解决方案,我无法翻译给定的内容。 Any kind of help will be appreciated.
任何形式的帮助将不胜感激。
Thanks! 谢谢!
you dont have to equal to false with function_exists. 你不必用function_exists等于false。 function_exists will check if function exists or not
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.