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/tutorial。

时使用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);
}

最新更新