PHP - gettext is not changing the language after installing to wamp 3
Posted by: fahani (---.162.216.87.static.jazztel.es)
Date: October 18, 2016 09:32AM

Morning,

I have a php project that uses the gettext functionality to translate the texts. I have two languages in my project, Spanish and English.

The language file structure is the next:

/locale/en_US/LC_MESSAGES/plantasenelaire.mo
/locale/es_ES/LC_MESSAGES/plantasenelaire.mo

The php code that I am using to select one language or another is the next:

if($languageCode == "en"winking smiley
{
$languageEncode = "en_US";
}
elseif($languageCode == "es"winking smiley
{
$languageEncode = "es_ES";
}
else
{
$languageEncode = "en_US";
}

putenv("LC_ALL=$languageEncode"winking smiley;
setlocale(LC_ALL, $languageEncode);

bindtextdomain("plantasenelaire", "./locale/"winking smiley;
textdomain("plantasenelaire"winking smiley;
bind_textdomain_codeset("plantasenelaire", 'UTF-8');

The code works just fine when using wamp 2.4 (32bits) with Apache 2.4.4 and PHP 5.4.16 on my Windows 7 64 bits.

The code also works fine on my linux shared hosting when using PHP 5.6 or PHP 7

Today I decided uninstall my wamp 2.4 and upgrade to wamp 3 with Apache 2.4.23 – PHP 5.6.25/7.0.10. I have installed all the Visual C++ Packages needed and then installed wamp 3 64 bits.

The code works but the language is always in Spanish no matter what I do. Always Spanish no matter if I use PHP 5.6 or 7.

I have tried multiples combinations and codes for the putenv and setlocale functions that I have found on the Internet without any luck :/

After trying wamp 3 (32 and 64 version) I went back to wamp 2.4, just to check if any of the Visual C++ Packages I installed messed up something on my Windows...

Everything works fine on wamp 2.4 with Apache 2.4.4 and PHP 5.4.16. It also works fine in my hosting as I said with PHP 5.6 and 7.

I don't know why is happening this.

Anyone can help me here? Any suggestion is welcomed.

Thank you a lot!

Options: ReplyQuote
Re: PHP - gettext is not changing the language after installing to wamp 3
Posted by: RiggsFolly (Moderator)
Date: October 18, 2016 09:51AM

Did you check the error logs?

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: PHP - gettext is not changing the language after installing to wamp 3
Posted by: fahani (---.162.216.87.static.jazztel.es)
Date: October 18, 2016 10:05AM

Hello RiggsFolly, thank you for your time man.

php error log is empty

apache error log:

[Tue Oct 18 09:55:33.416902 2016] [mpm_winnt:notice] [pid 2824:tid 336] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Tue Oct 18 09:55:35.417017 2016] [mpm_winnt:notice] [pid 4852:tid 160] AH00364: Child: All worker threads have exited.
[Tue Oct 18 09:55:35.437018 2016] [mpm_winnt:notice] [pid 2824:tid 336] AH00430: Parent: Child process 4852 exited successfully.
[Tue Oct 18 09:55:37.281123 2016] [auth_digest:notice] [pid 8648:tid 336] AH01757: generating secret for digest authentication ...
[Tue Oct 18 09:55:37.327126 2016] [mpm_winnt:notice] [pid 8648:tid 336] AH00455: Apache/2.4.23 (Win64) PHP/5.6.25 configured -- resuming normal operations
[Tue Oct 18 09:55:37.327126 2016] [mpm_winnt:notice] [pid 8648:tid 336] AH00456: Apache Lounge VC14 Server built: Jul 1 2016 11:43:51
[Tue Oct 18 09:55:37.327126 2016] [core:notice] [pid 8648:tid 336] AH00094: Command line: 'c:\\wamp64\\bin\\apache\\apache2.4.23\\bin\\httpd.exe -d C:/wamp64/bin/apache/apache2.4.23'
[Tue Oct 18 09:55:37.329126 2016] [mpm_winnt:notice] [pid 8648:tid 336] AH00418: Parent: Created child process 9056
[Tue Oct 18 09:55:37.814154 2016] [auth_digest:notice] [pid 9056:tid 160] AH01757: generating secret for digest authentication ...
[Tue Oct 18 09:55:37.861156 2016] [mpm_winnt:notice] [pid 9056:tid 160] AH00354: Child: Starting 64 worker threads.


I have been playing around with this code:

putenv("LC_ALL=en-US"winking smiley;
var_dump( setlocale(LC_ALL, "en-US"winking smiley);
var_dump( setlocale(LC_ALL, 0));


bindtextdomain("plantasenelaire", "./locale/"winking smiley;
textdomain("plantasenelaire"winking smiley;
bind_textdomain_codeset("plantasenelaire", 'UTF-8');

echo _("POSTAL_CODE"winking smiley;
die;

changing from /locale/en_US/LC_MESSAGES/plantasenelaire.mo to /locale/en-US/LC_MESSAGES/plantasenelaire.mo

restarting the server

output of the php is:


C:\wamp64\www\plants\libs\Bootstrap.php:137:string 'en-US' (length=5)

C:\wamp64\www\plants\libs\Bootstrap.php:138:string 'en-US' (length=5)

Código postal

if I rename locale/es_ES/LC_MESSAGES/plantasenelaire.mo to /locale/es_ES/LC_MESSAGES/xyz.mo and restart, the output is:

C:\wamp64\www\plants\libs\Bootstrap.php:137:string 'en-US' (length=5)

C:\wamp64\www\plants\libs\Bootstrap.php:138:string 'en-US' (length=5)

"POSTAL_CODE"

if I rename locale/en_US/LC_MESSAGES/plantasenelaire.mo to /locale/es_ES/LC_MESSAGES/plantasenelaire.mo and restart, the output is:

C:\wamp64\www\plants\libs\Bootstrap.php:137:string 'en-US' (length=5)

C:\wamp64\www\plants\libs\Bootstrap.php:138:string 'en-US' (length=5)

Postal code

It seems it goes to the es_ES directory no matter what.

Options: ReplyQuote
Re: PHP - gettext is not changing the language after installing to wamp 3
Posted by: Otomatic (Moderator)
Date: October 18, 2016 10:05AM

Hi,

To use gettext you have to follow some requirements: [fr2.php.net] and install gettext 0.19.8.1 and iconv 1.14 - Binaries for Windows

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: PHP - gettext is not changing the language after installing to wamp 3
Posted by: fahani (---.162.216.87.static.jazztel.es)
Date: October 18, 2016 10:26AM

Hi,

Installed and restarted OS, nothing has changed :/ Was it needed for the 3.0.6 wamp version? The thing is that the code works in wamp 2.4 (32bits) with Apache 2.4.4 and PHP 5.4.16 or in my shared hosing with linux and php 5.6 or 7

Any way to debug why is always reading from the es_ES ?

Thank you guys

Options: ReplyQuote
Re: PHP - gettext is not changing the language after installing to wamp 3
Posted by: Otomatic (Moderator)
Date: October 18, 2016 11:09AM

Hi,

> The thing is that the code works in wamp 2.4 (32bits) with Apache 2.4.4 and PHP 5.4.16
> or in my shared hosing with linux and php 5.6 or 7
Compare PHP extensions and Apache modules loaded.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: PHP - gettext is not changing the language after installing to wamp 3
Posted by: fahani (---.162.216.87.static.jazztel.es)
Date: October 18, 2016 12:10PM

Hi,

Yeah I did but still not working.

The only work around I can think of is to put all the language.mo files under the es_ES folder and then change the domain depending to the language to load.

I just don't get it what is going on, driving me crazy this issue.

what have changed in the wamp version to make not work the setlocale and putenv functions?

Thanks

Options: ReplyQuote
Re: PHP - gettext is not changing the language after installing to wamp 3
Posted by: Otomatic (Moderator)
Date: October 18, 2016 12:27PM

Hi,

Wampserver is not responsible for changes in the versions of PHP and Apache.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote


Sorry, only registered users may post in this forum.