开发者

gettext working locally, but not on the host server

开发者 https://www.devze.com 2023-02-16 07:31 出处:网络
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).

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?


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.


An old question, but I wanted to explain why it worked on Windows and not on Linux. Windows servers don't use the same locale names as Linux servers. For example, in Windows you will have "en", but on Linux you'll have "en_EN". It's the same with Polish, on Windows it will be "pl" and on Linux it will be "pl_PL". You'll need to have some type of test for your local or live server and change the locale string accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号