Search code examples
phpgettextphp-gettext

gettext working locally, but not on the host server


I'm facing an odd issue with gettext in my PHP application. It works on my development machines (Ubuntu 10.10 32 bit, 2 x Windows 7 64 bit, Windows 7 32 bit, all running XAMPP).

The production server is a paid host running some flavour of Linux 64 bit. I don't know exactly which. I can try to find out if it matters.

Here is how I initialise gettext:

//just FYI:
//$this->data['language'] == 'pl'
//dirname(__FILE__).'/../language/locale' ==
//'/home/mingos/public_html/example.com/application/controllers/../language/locale'

putenv('LANGUAGE='.$this->data['language']);
putenv('LANG='.$this->data['language']);
putenv('LC_ALL='.$this->data['language']);
setlocale(LC_ALL,$this->data['language']);

bindtextdomain($this->data['language'], dirname(__FILE__).'/../language/locale');
bind_textdomain_codeset($this->data['language'],'UTF-8');
textdomain($this->data['language']);

I ran phpinfo() on the server and found out that gettext is enabled and safe_mode is off, excluding the possibility LC_ALL being unmodifiable (I think).

The compiled gettext catalog is:

/home/mingos/public_html/example.com/application/language/locale/pl/LC_MESSAGES/pl.mo

So the path set in bindtextdomain is correct.

I do not get any notices or warnings, but gettext does not extract translations from my the catalog, returning simply the strings it is fed, e.g. gettext('About us') returns About us instead of O nas.

The catalog itself is compiled correctly using poEdit and is confirmed to be working on my 4 dev machines.

What might be the other possible causes of this?


Solution

  • gettext will only support the installed locales. If you have a shell on your hosting provider you should run 'locale -a' to see a list of installed locales. You may need to contact your hosting provider to have them install the necessary language pack for pl.