What I tried :

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

My translation files (*.mo, *.po) are under /usr/local/php/include/myapp/i18n/locale/ e.g /usr/local/php/include/myapp/i18n/locale/da_DK/LC_MESSAGES/generic.mo

I have put /etc/php5/conf.d/gettext.ini

extension=gettext.so

apache2 restart gives me this error :

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. 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.

有帮助吗?

解决方案

So this mystery resolved by excellent SOQ

One of the comment for gettext on php.net says:

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)
  2. locale -a (confirmed da_DK locale loaded)
  3. mv da_DK da_DK.utf8 (renamed the locales dir) bind_textdomain_codeset('messages', 'UTF8');

    One of the debugging point for me was setlocale(LC_ALL, 'da_DK.utf8'); which was returning false for invalid/non-existent locales

What about gettext.so extension:

The php installation I got through apt-get seems to have the extension added during compilation We can see if gettext is compiled module e.g php -m |grep gettext , which seems to be true ! I don't need gettext.ini, which is desired only when PHP is compiled --with-gettext=shared, which is not the case here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top