0
votes

I am trying to translate my PHP project using gettext, but it does not work. PHP output gettext string names and not the actual translation. .po files compiled in POeditor.

Setting locale:

// $language = 'en';
// $domain is the same as .mo file name
putenv("LANG=" . $language);
putenv("LANGUAGE=" . $language);
setlocale(LC_ALL, $language); // Also tried with .utf8 at the end
bindtextdomain($domain, 'locale'); // Also tried full path
textdomain($domain);

PO file: (in locale/en/LC_MESSAGES/filename.po)

msgid "SETUP_UI"
msgstr "User Interface"

msgid "SETUP_ACCOUNT"
msgstr "Account and Login"

... and so on

Echoing in PHP:

<?= gettext('SETUP_UI') ?>

Yes, I tried everything from stackoverflow - Googling for more than 3 hours. I have gettext installed in PHP, also tried to restart Apache, recompile .po files...

The result in browser is:

SETUP_UI

Thanks for your answers.

1

1 Answers

0
votes

You need to compile your .po files to .mo (which is what gettext consumes)