umpirsky
umpirsky

Reputation: 10024

PHP gettext does not work

Gettext simply does not work for me:

    putenv('LC_ALL=zh_CN.utf8');
    setlocale(LC_ALL, 'zh_CN.utf8');
    bindtextdomain('messages', __DIR__.'/locale');
    textdomain('messages');

messages.mo location is locale/zh_CN.utf8/LC_MESSAGES.

$locale -a
C
en_AG
en_US.utf8
en_ZA.utf8
en_ZW.utf8
POSIX
zh_CN.utf8
zh_SG.utf8

I'm on Ubuntu.

Any idea?

Upvotes: 2

Views: 3920

Answers (2)

Anderson Possamai
Anderson Possamai

Reputation: 11

For me, it worked by restarting apache.

Upvotes: 0

Smar
Smar

Reputation: 8591

Judging this note, you are most likely missing UTF-8 bits. Those helped me with problem of “Gettext not working”.

$directory = dirname(__FILE__).'/locale';
$domain = 'mydomain';

$locale ="fi_FI.utf8";

//putenv("LANG=".$locale); //not needed for my tests, but people say it's useful for windows

setlocale( LC_MESSAGES, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');

Inside locale, there should be file structure of

./locale/pt/LC_MESSAGES/mydomain.mo

or similar.

Important: If the mo file is already read by Apache, it needs be restarted so that it can read the new file. In other words, there is some kind of caching system I don’t know about still.

Upvotes: 4

Related Questions