Search code examples
phpdebiangettext

i18n not working via php-fpm in debian


I have a strange issue here. Here is the code:

 cat ./test.php
<?php

setlocale(LC_ALL,"");
//setlocale(LC_MESSAGES,'ru');
//setlocale(LC_CTYPE,'ru');
putenv("LANG=ru");
putenv("LANGUAGE=ru");

$domain = 'messages';
bindtextdomain($domain, "./locale");
textdomain($domain);
//var_dump($r);
//exit;

echo gettext("Welcome to My PHP Application");
print "\n";
echo gettext("ololo");

Here are localization files:

find ./locale/
./locale/
./locale/ru
./locale/ru/LC_MESSAGES
./locale/ru/LC_MESSAGES/messages.mo
./locale/ru/LC_MESSAGES/messages.po
./locale/en
./locale/en/LC_MESSAGES
./locale/en/LC_MESSAGES/messages.mo
./locale/en/LC_MESSAGES/messages.po

When I'm executing the script via CLI, everything's okay:

php ./test.php
Добро пожаловать!
452231

But when I'm calling it from the web, I'm getting only:

Welcome to My PHP Application
ololo

What am I missing? I'm using Debian 8.6, nginx, php-fpm 5.6.29. Gettext and Intl modules are enabled in CLI and FPM configurations both.

Thanks!


Solution

  • the solution was made by author: the php-fpm.conf clear_env parameter was set to Yes by default: Prevents arbitrary environment variables from reaching FPM worker processes by clearing the environment in workers before env vars specified in this pool configuration are added it should be setted to No see the manual http://php.net/manual/en/install.fpm.configuration.php#clear-env