Search code examples
phplocalegettext

Issues with gettext php


Text translation via gettext does not work. Help me please

$translate = 'messages';

putenv("LC_ALL=en_US");
T_setlocale(LC_ALL, "en_US");

bindtextdomain($translate, _ROOT_DIR_."locale/");
textdomain($translate);
bind_textdomain_codeset($translate, 'UTF-8');

Folder structure:

locale -> en_US -> LC_MESSAGES -> messages.mo messages.po

Script messages.po :

msgid ""
msgstr ""
"POT-Creation-Date: 2017-05-03 15:53+0300\n"
"PO-Revision-Date: 2017-05-03 15:54+0300\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.1\n"
"X-Poedit-Basepath: .\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: en_US\n"

#: index.php:5
msgid "Bonjour tout le monde"
msgstr "Hello world"

Solution

  • You just had to comment out one line in the php.ini file. Like this -

    ;extension=php_gettext.dll