|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 22:00:02 2025 UTC |
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 :(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.zipI 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'); // ClientSame 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.