php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66265 gettext is not working anymore
Submitted: 2013-12-11 16:42 UTC Modified: 2014-11-21 13:17 UTC
Votes:37
Avg. Score:4.7 ± 0.6
Reproduced:37 of 37 (100.0%)
Same Version:11 (29.7%)
Same OS:31 (83.8%)
From: roeycohen at gmail dot com Assigned: ab (profile)
Status: Closed Package: Gettext related
PHP Version: 5.5.7 OS: windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: roeycohen at gmail dot com
New email:
PHP Version: OS:

 

 [2013-12-11 16:42 UTC] roeycohen at gmail dot com
Description:
------------
as simple as that, a code that used to work perfect now doesn't.
switching back to version 5.4.8 solves the problem.

i've made sure that in the php.ini the gettext extension is on
and also tried turning off OPCache, but it didn't help.
as a matter of fact, i've compared both php.ini to make sure that most options are the same.

Test script:
---------------
$domain = 'domain';

putenv("LC_ALL=en_US");
setlocale(LC_ALL, 'en_US');

$path = realpath('./locale');
bindtextdomain($domain, $path);
bind_textdomain_codeset($domain, "UTF-8");
textdomain($domain);

echo _('hello');

Expected result:
----------------
the text hello will be replaced with the string within the mo file.

Actual result:
--------------
the original string is returned.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-11 17:01 UTC] ab@php.net
-Assigned To: +Assigned To: ab
 [2013-12-11 18:14 UTC] ab@php.net
-Status: Assigned +Status: Feedback
 [2013-12-11 18:14 UTC] ab@php.net
Hi,

I can't confirm the behavior you describe, works fine here with 5.5.5 and 5.5.6 

Please check and post the following

- you've restarted the webserver 
- the .mo file is present and is correct
- the .mo file is under locale\en_US\LC_MESSAGES\domain.mo

There must be something else otherwise in your environment, if this doesn't help.

Thanks.
 [2013-12-12 10:42 UTC] roeycohen at gmail dot com
-Status: Feedback +Status: Assigned
 [2013-12-12 10:42 UTC] roeycohen at gmail dot com
Hi, this is a complete sample:
http://blossom-kc.com/download/php_gettext/gettext.zip
(php.ini is included).

this sample works for a friend of mine, but not on my machine (windows 8 + iis + 5.5.7)
also, i am using iisreset to the restart the server (and tried reboot).
 [2013-12-12 11:10 UTC] roeycohen at gmail dot com
ok, i found something, 

if i change the folder en_US to he_IL and also use these lines instead of the original ones:
putenv("LC_ALL=he_IL");
setlocale(LC_ALL, 'he_IL');

and restart the server then everything is working fine...

i didn't had this problem in version 5.4.8 :(
 [2013-12-12 11:15 UTC] roeycohen at gmail dot com
-PHP Version: 5.5.6 +PHP Version: 5.5.7
 [2013-12-12 11:15 UTC] roeycohen at gmail dot com
hmm, apparently, trying other locales, other than he_IL doesn't fix the problem...
i've tried: es_ES, en, 'dummy', fr_FR same result as en_US.

only he_IL fixes the problem, may it has something to do with my region format being "israel"?
 [2013-12-12 11:30 UTC] ab@php.net
-Status: Assigned +Status: Feedback -PHP Version: 5.5.7 +PHP Version: 5.5.6
 [2013-12-12 11:30 UTC] ab@php.net
Hi,

thanks for posting the experience. However on my machine your exact snippet worked. 

There's another point with gettext - the locale passed to gettext has to be present on the system. Same on Linux, the locale has to be present (that /etc/locale.gen stuff), on Windows it has to be installed along with the base locale. After your last discovery, is the base system locale on your machine he_IL? Please check that en_US support is installed as well.

Is the machine where 5.4 works the same where 5.5 fails? Also, to exclude IIS, could you please try the same on CLI?

Thanks.
 [2013-12-12 11:31 UTC] ab@php.net
-PHP Version: 5.5.6 +PHP Version: 5.5.7
 [2013-12-12 11:31 UTC] ab@php.net
ups, set back the php version
 [2013-12-12 11:57 UTC] roeycohen at gmail dot com
-Status: Feedback +Status: Assigned
 [2013-12-12 11:57 UTC] roeycohen at gmail dot com
My current locale is indeed he_IL: hebrew(israel).
i'm not sure how to install another locale... but my machine is able to display english characters :))

when i switch between php versions, i do it on the same machine: i stop iis, rename the php folders and start the server again.
 
I also ran the script using CLI and got the same results.
 [2013-12-16 18:05 UTC] ab@php.net
-Status: Assigned +Status: Feedback
 [2013-12-16 18:05 UTC] ab@php.net
Hi,

after further debugging it turned out, that the issue might be laying somewhere else. With CLI, could you please try the following

- set LANG=en_US
- run php snippet.php

After that your first snippet works as well. Could you confirm that?

To install additional locales, on win8 i go to 

Control Panel\All Control Panel Items\Language

Maybe that's edition dependent, but one could try.

Thanks
 [2013-12-17 08:53 UTC] roeycohen at gmail dot com
-Status: Feedback +Status: Assigned
 [2013-12-17 08:53 UTC] roeycohen at gmail dot com
it worked!:)
 [2014-01-21 15:32 UTC] alvaro at demogracia dot com
Not sure if it's the same issue (I'll be glad to open a separate ticket otherwise) but in my case gettext is always loading the same catalogue. There's no say to change the language from within PHP. It happens with every PHP/5.5 version (VC11 TS x86) I've tried: 5.5.5, 5.5.6, 5.5.8... However, it works as expected with PHP/5.4 (VC9 TS x86).

I have this test code [1] I run from the command-line in a Windows 7 (x64) with Spanish locale:

    <?php

    if(!defined('LC_MESSAGES')){
    	define('LC_MESSAGES', 5);
    }

    bindtextdomain('gettext', __DIR__ . '/locale');
    bind_textdomain_codeset('gettext', 'UTF-8');
    textdomain('gettext');
    
    
    $languages = array(
    	'es',
    	'es_ES',
    
    	'en',
    	'en_GB',
    
    	'english',
    	'english-uk',
    	'uk',
    	'britain',
    	'england',
    	'eng',
    
    	'totally_invalid',
    );

    foreach($languages as $locale){
    	putenv("LC_ALL=$locale");
    	echo $locale . ': ' . _('__translate_this__') . PHP_EOL;
    }

In PHP/5.4 I get this:

    es: Loaded from Spanish catalogue
    es_ES: Loaded from Spanish catalogue
    en: Loaded from English catalogue
    en_GB: Loaded from English catalogue
    english: __translate_this__
    english-uk: __translate_this__
    uk: __translate_this__
    britain: __translate_this__
    england: __translate_this__
    eng: __translate_this__
    totally_invalid: __translate_this__

In PHP/5.5 I get this:

    es: Loaded from Spanish catalogue
    es_ES: Loaded from Spanish catalogue
    en: Loaded from Spanish catalogue
    en_GB: Loaded from Spanish catalogue
    english: Loaded from Spanish catalogue
    english-uk: Loaded from Spanish catalogue
    uk: Loaded from Spanish catalogue
    britain: Loaded from Spanish catalogue
    england: Loaded from Spanish catalogue
    eng: Loaded from Spanish catalogue
    totally_invalid: Loaded from Spanish catalogue

Just to be sure, I've tested it with stripped down PHP installations:

    php-5.5.8-oficial-VC11
    │   php.exe
    │   php.ini
    │   php5ts.dll
    │
    └───ext
           php_gettext.dll

... where php.ini only contains this:

    [PHP]
    extension_dir = "ext"
    extension=php_gettext.dll

... and I manually clean up PATH before running my tests:

    PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem

Setting a LANG variable manually from command prompt *does* change the catalogue (I get "Loaded from English catalogue" every time):

    set LANG=en_US

... but setting it from PHP itself (though apparently successfull) doesn't affect the loaded catalogue at all:

    var_dump( putenv('LANG=en_US'), getenv('LANG') );
    bool(true)
    string(5) "en_US"
    
I've tried every variation of putenv() or setlocale() I've been able to think about.



[1] Test code: http://alvaro.es/archivos/gettext-bug-66265.zip
 [2014-02-25 16:28 UTC] swbva at thecloudindex dot com
Same kind of problems here...

PHP 5.4 works fine, PHP 5.5 doesn't
I'm on Win7-64.

Correct locale identifiers (region & language) for Windows can be found in this table (last 2 columns):
http://www.microsoft.com/resources/msdn/goglobal/default.mspx
(But, as some may know of course, other ways to indicate the locale on Windows are possible, see e.g.: http://msdn.microsoft.com/en-us/library/39cwe7zf%28v=vs.100%29.aspx)

There DO seem to be some inconsistencies in PHP 5.5.
For example; setting a locale named 'en' seems to be valid. PHP 5.4 returns (correctly?) false

A little comparison ('locale': setlocale() return string):

5.4
en: false
en_US: false
en-US: false
enu:  English_United States.1252

5.5
en: en
en_US: false
en-US: en-US
enu: English_United States.1252


Windows seem to add the codepage the the locale string. Since my language files are in utf-8 (not cp1252), I hope this doesn't cause troubles?
It doesn't seem possible to add the encoding the the locale string in Windows.
(Btw; of course, it IS working in PHP 5.4 already..)

Another thing: what seems to work in PHP 5.4, is e.g. using putenv("LC_ALL=en"), with my english LC_MESSAGES in a folder named 'en'.
Of course this isn't a valid (Windows) locale, but it IS what I want regarding Gettext in my case (1 file for the english language, disregarding region).

Is this a valid practice? I believe the LC_ALL variable is temporary set/altered, and immediately restored to it's original/previous value after PHP is finished with Gettext? (So if it is working, it doesn't do any possible harm?)

Btw; only LC_ALL env. variable seems to matter for gettext?
I seems I can use anything for setlocale, and Gettext still will get the right file? (on Win/PHP 5.4 anyway..)


Ps; I am wondering what exactly worked for roeycohen (and how?)
I can reproduce his problem, but can't solve it?
 [2014-02-25 16:44 UTC] swbva at thecloudindex dot com
Oh yes, @ab; of course it seems to me this isn't a case of having the right languages installed?

On Win7, there is 'Region and Language', I guess all that are in the 'format' dropdown are supported (probably the same list as on the page the first link I've given in my previous post is pointing to).

And of course, it IS workin in PHP 5.4... So (at least) it /looks/ like the OS / 'installed' 'languages' isn't the problem?

Thanks
 [2014-03-06 14:53 UTC] barry at staes dot nl
I experienced the regression when upgrading from XAMPP 1.8.2 to 1.8.3, which was using PHP 5.4.19 and PHP 5.5.6 respectively. Its easily reproduced, both on Windows 7 and 8.1. First setlocale(LC_MESSAGES, 'nl_NL.UTF8') works, but after upgrade it wont. 

On a sidenote, the OS does not need to have the locales i was using via PO files installed, or have matching names at all, but it worked excelent nonetheless. Now  it always sets the locale to the OS language, and loads that PO files. No matter what setlocale() gets called with.
 [2014-04-29 14:52 UTC] gab at forme dot it
I have the same problem on win 7 64bit, after upgrading to xampp 1.8.3 (php 5.5.9) gettext doesn't work. With previous xampp 1.8.2 (php 5.4.27) gettext works fine.
 [2014-05-15 05:00 UTC] e at elasten dot eu
I have almost the same problem on Win7 64bit. The script is using the system default locale (Hungarian) to load the .po file and not the setlocale/putenv variables, but interestingly for me PHP 5.3.28b works and neither 5.4.28a and 5.5.12a. I am using Uniform Server Zero XI which can switch loaded PHP version with a restart of the server.
 [2014-05-16 07:50 UTC] louisantoinem at gmail dot com
same problem on PHP 5.5.9 Ubuntu 14.04
gettext seems to always select the same catalogue
worked with the exact same source code in PHP 5.3
 [2014-05-19 11:50 UTC] louisantoinem at gmail dot com
For me, fixed by adding the needed locales, in my case:

locale-gen fr_FR.UTF-8
 [2014-05-19 12:16 UTC] barry at staes dot nl
louisantoinem: that is not this PHP bug on Windows. (i tried adding locales but no success)
The problem here is same code stops working after PHP upgrade.


Comments/tests summarized so far:

Works:
PHP 5.3 : 5.3.28b (*1)
PHP 5.4 : 5.4.8, 5.4.19

Does not work:
PHP 5.4 : 5.4.28a (*1)
PHP 5.5 : 5.5.5, 5.5.6, 5.5.7 (*2), 5.5.8, 5.5.9, 5.5.12a (*1)


I assume all tested in Apache, except for
*1) tested in Uniform Server Zero XI by e@elasten.eu
*2) tested in ISS by roeycohen@gmail.com

More specific tests are welcome. (Windows + PHP + gettext..)
 [2014-05-19 12:34 UTC] barry at staes dot nl
So that might narrow it down to 5.4.19 .. 5.4.28a

Can anyone else confirm behavior for these PHP versions on Windows? 
Can anyone test the intermediates .. when was the problem introduced?

I dont know how to quickly switch out PHP versions. Or is there a ZEND hosted test facility for reproducing these things?
 [2014-06-17 07:14 UTC] revx at gmx dot de
I can confirm this problem for PHP Version 5.5.9.
I'm using Windows 7 64-Bit on a german computer.
Currently the only solution is to change the Windows language settings under:

1. Control panel > Regional and Language Options > Format > Französisch (Schweiz)
2. Restart Apache

// This will return false 
echo setlocale(LC_ALL, 'fr_CH'); // false

// but the translation works.
echo __('Kunde'); // Client
 [2014-07-31 07:50 UTC] az at tass dot de
Same here ... 

OS: Windows 7 Enterprise SP1
IIS Express 8.0.8418

PHP 5.5.14 --> same issue as submitted, Bug #66265

switching to 
PHP 5.3.28 --> resolves the issue and gettext works how it should be
 [2014-09-30 18:34 UTC] jin at 2acom dot com
got the same problem on windows 8, wamp 2.5 (64bit) and php 5.5.12
 [2014-10-27 09:31 UTC] dalahimself at hotmail dot com
Had similar problem. Was running XAMPP 1.8.3 (Php 5.5.15) on Windows 2008 R2 sever and could not get gettext to work.
Installed XAMPP 1.8.1 (Php 5.4.7) instead, and now things work just fine.
 [2014-11-18 19:08 UTC] goozak at gmail dot com
Bug still present in PHP 5.5.19.
(Wondering if assigned user ab is still working on this, he hasn't commented since 2013.)
 [2014-11-21 09:25 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=56fac96bec882ac59a7fc298c98407bf4a17629d
Log: partially fixed bug #66265
 [2014-11-21 09:25 UTC] ab@php.net
-Status: Assigned +Status: Closed
 [2014-11-21 13:17 UTC] ab@php.net
-Status: Closed +Status: Re-Opened
 [2014-11-21 13:17 UTC] ab@php.net
I want to gratefully thank everyone who reported here and kindly ask to test this or later NTS snapshot http://windows.php.net/downloads/snaps/php-5.5/rf2e33dc/  .

Yes, TS builds are still not fixed and there is no certainty they can be fixed, that's why i reopen this. Even I'd rather mark this ticket as solved and move the remaining issue to another one. As locale is not thread safe (for instance see bug #65769). Fortunately gettext isn't really based on the locale functionality but on the exported vars, like LANGUAGE, LANG, LC_ALL or LC_CTYPE. It might be also that the libintl will have to be patched once more to support TS builds. It also seems that something has changed from VC9 to VC11 so then it affects the behaviour of the libintl.

One note though about the snippets brought here so far, the following won't work on windows

setlocale(LC_ALL, 'de_DE');

de_DE isn't a valid locale on Windows, so the former should look like

setlocale(LC_ALL, 'de_DE', 'de-de');

and actually it could contain any number of locale names. While setlocale on windows wont directly affect the gettext behaviour, merely it's an environment varibale as mentioned before.

Thanks.
 [2014-11-26 16:21 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=56fac96bec882ac59a7fc298c98407bf4a17629d
Log: partially fixed bug #66265
 [2014-11-26 16:21 UTC] ab@php.net
-Status: Re-Opened +Status: Closed
 [2015-03-06 11:51 UTC] alvaro at demogracia dot com
Is there a new ticket for TS builds?
 [2015-04-29 22:29 UTC] sirio3mil at gmail dot com
Hi, I have same problem with PHP 5.6.6 and 5.6.7 both TS x64 running on Apache over Windows Server 2008 R2 and Windows 10 TP.

I get only the translations to the default system lamguage (Control Panel) Temporary I change location from all my .mo files to this folders and change domain to get correct translations.
 [2015-12-02 11:10 UTC] lafleurpy at gmail dot com
Same issue with wamp server 2.5 32bits on Windows 7 (with PHP : 5.5.12).

I confirm the trick given by sirio3mi to make gettext working.

It seems that only the folder with the current system locale is readable (for me /fr_BE). Dictionaries in others directories (as /nl_BE) can't be loaded. 

So I put all my POedit dictionaries in /fr_BE/LC_MESSAGES/ and named them with their corresponding locale (ex : nl_BE.mo + nl_BE.po).

It's maybe dirty, but it works.

Here is the PHP code :

bind_textdomain_codeset ({your locale}, {your char codeset}); 

bindtextdomain ({your locale}, {absolute path to locale directory});

textdomain ({your locale});

setlocale (LC_ALL,{your locale});

putenv('LC_ALL=' . {your locale});


For making short : use the same locale directory but change the domain when you change the language.
 [2015-12-02 12:03 UTC] roeycohen at gmail dot com
to work around this issue, i moving to translation arrays.
since php 5.5 when opcache is on, the performance of loading an array of translation or the mo file is about the same (at least from my benchmarks).
 [2016-06-24 09:18 UTC] dev at ms-software dot de
It seem’s, that gettext with virtual server on Windows doesn’t work. If I install it to localhost all thinks work well, on my virtual server, gettext do not translate anything!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 20:01:29 2024 UTC