【问题标题】:Setting up gettext for php under ubuntuubuntu下为php设置gettext
【发布时间】:2014-04-22 18:51:00
【问题描述】:

我尝试了什么:

  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 restart 给了我这个错误:

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/gettext.so' - /usr/lib/php5/20090626/gettext.so: cannot open shared object file: No such file or directory in Unknown on line 0

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

php --version PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/gettext.so' - /usr/lib/php5/20090626/gettext.so: cannot open shared object file: No such file or directory in Unknown on line 0 PHP 5.3.10-1ubuntu3.10 with Suhosin-Patch (cli) (built: Feb 28 2014 23:14:25) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

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

【问题讨论】:

  • 是的,我已经做到了。
  • 你可以试试locate gettext.so 看看它是否建在不同的位置。如果是这样,请尝试修改 php.ini 文件中的指令。
  • 有什么理由不投票?
  • 另外,你确定/etc/php4 是正确的吗?您使用的是 5.3.x,而不是版本 4。
  • 我已经从 php --version 的命令行截取过去。它的 php5,这是错字对不起

标签: php apache ubuntu gettext


【解决方案1】:

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

php.net 上 gettext 的 comment 之一说:

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('messages', 'UTF8');

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

gettext.so 扩展怎么样:

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

【讨论】:

  • 我在为各种环境设置 gettext 时遇到了相当多的问题,即在 Ubuntu 和 Windows 上的 XAMPP(包括此处的语言环境)。我已将它们全部记录在我博客上的一篇文章中,供仍在为这些问题苦苦挣扎的任何人使用:blog.terresquall.com/2020/09/troubleshooting-php-gettext
猜你喜欢
  • 2015-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-24
  • 1970-01-01
相关资源
最近更新 更多