PHP gettext function only returns orignal untranslated string
- by Camsoft
I'm trying to use gettext add localisation support to my website. I've followed various guides on how to setup gettext and have done the following:
I've created the following files and directories in the root of my project dir:
test.php
locale/
de_DE
LC_MESSAGES
messages.mo
messages.po
en_GB
LC_MESSAGES
messages.mo
messages.po
I've used Poedit to create the above .po and mo files. I've made sue it use Unix line endings, UTF-8 and set the language and country accordingly.
I've then created a PHP script called test.php which has the following code:
<?php
define('LOCALE', 'de_DE');
// Set up environmental variables
putenv("LC_ALL=" . LOCALE);
setlocale(LC_ALL, LOCALE);
bindtextdomain("messages", "./locale");
bind_textdomain_codeset("messages", LOCALE .".utf8");
textdomain("messages");
die(gettext('This is a test.'));
?>
I've imported the text "This is a test." to Poedit and supplied the translation and saved it.
But for some reason the test.php script will only output the original text untranslated. It refuses to load the version for the translation files.
It's worth noting that the server is running Linux (Ubuntu),
Apache 2.2.11 and PHP 5.2.6-3ubuntu4.5. I've checked phpinfo() and gettext is enabled.
Can someone help me? Thanks.