php - I18n 使用 PHP gettext()

标签 php internationalization translation 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、*.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/

相关文章:

php - 写入 csv 文件。 ' ; ' 下一列不起作用

iphone - 自动化Localizable.strings?

PHP PDO 绑定(bind)问题

php - 无法使用 pdo 获取行 ID

angular - Angular (@angular/localize)是否可以进行运行时语言翻译?

android - Android 上的二维四边形 : Translation with OpenGL ES 2. 0

xml - 翻译xml文件中的字符串

c++ - c++\linux 中的 translate_address

php - Android登录并注册MySQL HTTPS网站

django - set_language View 给我一个 "Page not found"错误