There is a php code in the / var / www / html / folder:

// Задаем текущий язык проекта putenv("LANG=ru_RU"); // Задаем текущую локаль (кодировку) setlocale (LC_ALL, "Russian"); // Указываем имя домена $domain = 'flowchart'; // Задаем каталог домена, где содержатся переводы bindtextdomain('flowchart', "/var/www/html/admin/modules/flowchart/i18n"); // Выбираем домен для работы textdomain('flowchart'); echo gettext('test'); 

and valid localization files in / var / www / html / admin / modules / flowchart / i18n This example displays "test" though:

 msgid "test" msgstr "тест" 

But I copied the / var / www / html / admin / modules / flowchart / i18n folder into the / var / www / html / folder and changed the bindtextdomain ('flowchart', "/ var / www / html / admin / modules / flowchart / i18n ") on bindtextdomain ('flowchart'," ./i18n ") then it all started and issued a" test ".

 echo file_get_contents('/var/www/html/admin/modules/flowchart/i18n/ru_RU/LC_MESSAGES/flowchart.mo'); 

correctly displays the contents of the file

What could be the problem? I tried everything again: I put chmod 7777 everywhere, rewritten the directory and recompiled the .mo file, tried different variations of the localization call, etc.
There is only one result: from the root it works, but from the position it does not.

  • so you have a homepage here is /var/www/html/admin/modules/flowchart/i18n/ru_RU/LC_MESSAGES/ and you point to /var/www/html/admin/modules/flowchart/i18n in the function. - Naumov

2 answers 2

It seems to be all right. And what, if so specify?

 bindtextdomain($domain, './admin/modules/flowchart/i18n') 

In the case of gettext , the output to the screen of the results of each command ( setlocale , bindtextdomain , etc.), and reading the documentation on the returned results, because if setlocale returns false , then further commands are simply useless.

  • Displays (command | result): putenv ("LANG = en_RU") | 1 setlocale (LC_ALL, "Russian") | Russian bindtextdomain ($ domain, './admin/modules/flowchart/i18n') | / var / www / html / admin / modules / flowchart / i18n textdomain ('$ domain') | flowchart gettext ('test') | test - ErrorMan
  • If the script works under php-fpm, then try restarting it. - Zhukov Roman
  • No, everything works through Apache - ErrorMan
  • The Apache has distorted - was got! Apparently gettext aggressively caches records. - ErrorMan

It was necessary to restart the worker pulling php. In my case, apache gettext aggressively caches records.