简体   繁体   English

在ubuntu下为php设置gettext

[英]Setting up gettext for php under ubuntu

What I tried : 我尝试了什么:

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

My translation files (*.mo, *.po) are under /usr/local/php/include/myapp/i18n/locale/ eg /usr/local/php/include/myapp/i18n/locale/da_DK/LC_MESSAGES/generic.mo 我的翻译文件(* .mo,* .po)位于/usr/local/php/include/myapp/i18n/locale/ eg /usr/local/php/include/myapp/i18n/locale/da_DK/LC_MESSAGES/generic.mo

I have put /etc/php5/conf.d/gettext.ini 我放了/etc/php5/conf.d/gettext.ini

extension=gettext.so

apache2 restart gives me this error : 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

What I am doing wrong ? 我做错了什么? As far as I remember this is standard way to install an extension under linux. 据我所知,这是在linux下安装扩展的标准方法。 This is working fine at my local system, but not on an amazon instance. 这在我的本地系统上工作正常,但不适用于亚马逊实例。

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

please guide me to setup this extension on ubuntu. 请指导我在ubuntu上设置此扩展程序。

So this mystery resolved by excellent SOQ 因此优秀的SOQ解决了这个谜团

One of the comment for gettext on php.net says: 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...

My issue resolved exactly by following these steps: 我的问题完全按照以下步骤解决:

  1. sudo apt-get install language-pack-da-base (danish) sudo apt-get install language-pack-da-base(danish)
  2. locale -a (confirmed da_DK locale loaded) locale -a(已确认da_DK语言环境已加载)
  3. mv da_DK da_DK.utf8 (renamed the locales dir) bind_textdomain_codeset('messages', 'UTF8'); mv da_DK da_DK.utf8(重命名为locales dir) bind_textdomain_codeset('messages', 'UTF8');

    One of the debugging point for me was setlocale(LC_ALL, 'da_DK.utf8'); 对我来说,其中一个调试点是setlocale(LC_ALL, 'da_DK.utf8'); which was returning false for invalid/non-existent locales 对于无效/不存在的语言环境,它返回false

What about gettext.so extension: gettext.so扩展名怎么样:

The php installation I got through apt-get seems to have the extension added during compilation We can see if gettext is compiled module eg php -m |grep gettext , which seems to be true ! 我通过apt-get获得的php安装似乎在编译期间添加了扩展我们可以看看gettext是否是编译模块,例如php -m |grep gettext ,这似乎是真的! I don't need gettext.ini , which is desired only when PHP is compiled --with-gettext=shared , which is not the case here. 我不需要gettext.ini ,这只有在编译PHP时才需要--with-gettext=shared ,这不是这里的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM