My system is Ubuntu 14.04.1, with apache 2 with PHP 5.5.9-1ubuntu4.22
Problem: I want to translate my web application made in PHP with Gettext and I can not get it translated. So I created a new project with the minimum necessary to make translations work.
My project has the following structure:
TESTGETTEXT (nombre del proyecto)
- Locale
- en_GB
LC_MESSAGES
en_GB.mo
en_GB.po
- es_ES
LC_MESSAGES
es_ES.mo
es_ES.po
- index.php
The content of my index.php
is as follows:
session_start();
$language = "es_ES";
if (isset($_GET['language']))
{
$language = $_GET['language'];
}
putenv("LANG=" . $language);
putenv("LC_ALL={$language}");
setlocale(LC_ALL, $language);
$domain = $language;
bindtextdomain($domain, "./Locale/");
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
if (function_exists("gettext"))
{
echo _("La función gettext existe");
}
else
{
echo _("La función gettext no existe");
}
echo '<br>' . $language . '<br>';
echo _("Hola mundo");
The content of my en_GB.po
file is as follows:
msgid ""
msgstr ""
"Project-Id-Version: test\n"
"POT-Creation-Date: 2017-08-31 10:38+0100\n"
"PO-Revision-Date: 2017-08-31 10:39+0100\n"
"Last-Translator: Jonathan López <[email protected]>\n"
"Language-Team: jlu <[email protected]>\n"
"Language: en_GB\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.4\n"
"X-Poedit-KeywordsList: _;gettext;gettext_noop\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: /home/jonathan/www/testGettext\n"
#: /home/jonathan/www/testGettext/index.php:22
msgid "La función gettext existe"
msgstr "The function gettext exist"
#: /home/jonathan/www/testGettext/index.php:26
msgid "La función gettext no existe"
msgstr "The function gettext doesn't exists"
#: /home/jonathan/www/testGettext/index.php:31
msgid "Hola mundo"
msgstr "Hello word!"
#: /home/jonathan/www/testGettext/index.php:32
msgid "Hola Jose"
msgstr "Hello Jose"
#~ msgid "Vamos a hacer una web multi-idioma."
#~ msgstr "We will make a multilingual website"
To verify that it works use the following URLs to modify the language:
- localhost / index.php? language = en_ES
- localhost / index.php? language = en_GB
The result I get:
La función gettext existe
en_GB
Hola mundo
and
La función gettext existe
es_ES
Hola mundo
In no case do you perform the translations. What is wrong with me? How can I find out the error?