php - ubuntu下设置php的gettext

标签 php apache ubuntu gettext

我试过的:

  1. sudo apt-get install php-gettext
  2. sudo apt-get install gettext
  3. sudo apt-get install locales

我的翻译文件(*.mo, *.po)在 /usr/local/php/include/myapp/i18n/locale/ 下 例如 /usr/local/php/include/myapp/i18n/locale/da_DK/LC_MESSAGES/generic.mo

我把/etc/php5/conf.d/gettext.ini 放在了

extension=gettext.so

apache2 重启给我这个错误:

PHP 警告:PHP 启动:无法加载动态库“/usr/lib/php5/20090626/gettext.so” -/usr/lib/php5/20090626/gettext.so:无法打开共享对象文件: 在第 0 行的未知中没有这样的文件或目录

我做错了什么?据我所知,这是在 linux 下安装扩展的标准方法。这在我的本地系统上运行良好,但在亚马逊实例上运行不正常。

php --version PHP 警告:PHP 启动:无法加载动态库 '/usr/lib/php5/20090626/gettext.so' -/usr/lib/php5/20090626/gettext.so:无法打开共享对象文件:没有这样的文件或目录在第 0 行未知 带有 Suhosin-Patch (cli) 的 PHP 5.3.10-1ubuntu3.10(构建时间:2014 年 2 月 28 日 23:14:25) 版权所有 (c) 1997-2012 The PHP Group Zend Engine v2.3.0,版权所有 (c) 1998-2012 Zend Technologies

请指导我在 ubuntu 上设置此扩展。

最佳答案

所以这个谜团被优秀的SOQ解开了

comment 之一对于 php.net 上的 gettext 说:

Warning for Linux (Ubuntu) users!  Your system will *only* support the locales installed on your OS, in the *exact* format given by your OS.  (See also the PHP setlocale man page.)  To get a list of them, enter locale -a, which will give you something like this:

C
en_US.utf8
ja_JP.utf8
POSIX

So this machine only has English and Japanese!  To add eg. Finnish, install the package:

sudo apt-get install language-pack-fi-base

Rerun locale -a, and "fi_FI.utf8" should appear.  Make sure you're using the same name in your PHP code:

setlocale(LC_ALL, "fi_FI.utf8");

Adjust your po paths so that they match, e.g. "./locale/fi_FI.utf8/LC_MESSAGES/messages.po".

Now restart Apache, and it should finally work.  Figuring this out took quite a while...

我的问题完全按照以下步骤解决:

  1. sudo apt-get install language-pack-da-base(丹麦语)
  2. locale -a(确认已加载 da_DK 语言环境)
  3. mv da_DK da_DK.utf8(重命名语言环境目录) bind_textdomain_codeset('消息', 'UTF8');

    我的调试点之一是 setlocale(LC_ALL, 'da_DK.utf8'); 对于无效/不存在的语言环境返回 false

关于 gettext.so 扩展名:

我通过apt-get得到的php安装貌似在编译的时候加了扩展 我们可以看到 gettext 是否是编译模块,例如 php -m |grep gettext ,这似乎是真的! 我不需要gettext.ini , 这只有在编译 PHP 时才需要 --with-gettext=shared ,这里不是这种情况。

关于php - ubuntu下设置php的gettext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22456520/

相关文章:

php - phpbb 上的 Cloudflare 用户 IP 问题

apache - Centos OS https 显示 apache2 默认页面

javascript - 使用ajax通过javascript提示验证密码

apache - mod_rewrite 表现不佳

php - 如何为每个目录自动将 PHP 错误保存到文件中?

ruby-on-rails - Ubuntu 12.04 - RubyOnRails - gem install mysql2 似乎已安装但在我执行 : gem mysql2 - Unknown command mysql2 时失败

objective-c - 在 Ubuntu 上找不到 Foundation 头文件

ubuntu - 已在 Virtualbox 中运行的 Ubuntu 中未启用 VT-X/AMD-v

PHP:如何将字符串作为参数传递而不用引号引起来?

php - 使用复合主键生成自增 ID