Gettext does not perform PHP web translations with the Nginx server

0

Thank you very much for your help.

My system is a Debian Jessy on a armv7l architecture. With Nginx server and PHP 5.6

Problem: I want to translate my web application made in PHP with Gettext and I can not get it translated. Peeeer this same code yes works correctly on the Apache server .

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:

<?php

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!"

I have also checked:

  • Have the Gettext installed on the target system of the application.
  • I have the gettext module activated in PHP ( phpinfo() shows that I have the module enabled).
  • I have the "locales" installed.

Those that I have installed and enabled:

# locale -a
C
C.UTF-8
en_GB.utf8
en_US.utf8
es_ES.utf8
it_IT.utf8
POSIX
ru_RU.utf8

To verify that it works use the following URLs to modify the language:

  • 192.168.1.15/index.php?language=en_US
  • 192.168.1.15/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 very strange to me is that it works exactly the same on my local Apache development server. How can I find out the error? Can someone tell me what difference there is in configuring the Apache server and Nginx in the translation topic?

I know that the quick solution would be to use Apache on the target machine, but it is an embedded system and it is a requirement to use the Nginx server.

Thank you very much for your contributions.

    
asked by Jonathan 04.04.2018 в 09:28
source

0 answers