2

Apache 2.4 + PHP 5.5

putenv('LC_ALL=ru_RU');
setlocale(LC_ALL, 'ru_RU');
bindtextdomain('mydomain', '/absolute/path/to/messages');
textdomain('mydomain');

I'm absolutely sure, than I've mydomain.po and mydomain.mo files in /absolute/path/to/messages/ru_RU/LC_MESSAGES/.
Also I gave these files to my colleague on OS X Maverics - worked fine.
I can't make php gettext working.

I've googled/stackoverflowed for about couple of hours, tried various solutions - still not working. What I do wrong?

I restart apache every time I change something to ensure gettext files is being reloaded.

Here is my locale -a output:

miraage@ubuntu:~$ locale -a
C
C.UTF-8
....
en_GB.utf8
....
POSIX
ru_RU.utf8
ru_UA.utf8

One more cmd output:

miraage@ubuntu:~$ sudo locale-gen ru
Generating locales...
  ru_RU.UTF-8... up-to-date
  ru_UA.UTF-8... up-to-date
Generation complete.

Okay, I've figured out:

sudo locale-gen ru_RU (added new locale, but different charset) and then setlocale(LC_ALL, 'ru_RU.UTF-8'); did all work.

Thanks for help.

Miraage
  • 3,334
  • 3
  • 26
  • 43
  • How exactly does it not work? You always get the same catalogue? You get not catalogue at all? And error message? What do `setlocale()` and `textdomain()` return? – Álvaro González May 14 '14 at 11:04
  • `setlocale()` returned `false`, `textdomain()` returned **mydomain**. Thanks for comment. Will try to figure out locale. – Miraage May 14 '14 at 11:06
  • I used `putenv('LANG=ru_RU');` - did not know that you set `LC_ALL` there? – Jurik May 14 '14 at 11:10
  • You possibly need `setlocale(..., 'ru_RU.utf8')`. `ru_RU` is not in `locale -a`'s output. – Álvaro González May 14 '14 at 11:17
  • Tried `ru`, `ru_RU`, `ru_RU.utf8`. Still no result. – Miraage May 14 '14 at 11:28
  • Did you set your codeset too? `bind_textdomain_codeset(, 'utf-8');` Well - this won't help you too thought, because your error is in setlocale. Did you try this `putenv` which I posted? – Jurik May 14 '14 at 11:30
  • @Jurik yes, tried both `utf8` and `UTF-8`. Maybe problem not in PHP? – Miraage May 14 '14 at 11:33
  • @Miraage since `setlocal` does not work, I thought the error must be before this and I did not know that you set `LC_ALL` at this place. So did you try `putenv('LANG=ru_RU');`? – Jurik May 14 '14 at 11:35
  • `putenv('LANG=ru');` `putenv('LANG=ru_RU');` `putenv('LANG=ru_RU.utf8');` `putenv('LANG=ru_RU.UTF-8');` nothing helped. – Miraage May 14 '14 at 11:37
  • Until `setlocale()` finally returns `true` there's nothing that locale based functions can do. Using `putenv()` simply skips error checking. – Álvaro González May 14 '14 at 14:13

1 Answers1

0

It is a long time asked question, but maybe one more check will help someone who will try everything "just by instruction" and still doesn't work.

That is collision with LANGUAGE environment variable.

In my case a while ago after a long fight, I figured out that it was causing the issue. Removing that environment variable export LANGUAGE= (empty, after =) resolved normal setLocale behavior.

Ilia Shakitko
  • 1,417
  • 2
  • 18
  • 25