I'm running into the same error. My case is a bit different, and I'm starting to think it has something to do with threading, despite it happens since I changed my code.
I have a language bar:
<?php
include_once (dirname(__FILE__) . "/resources/config.php");
?>
<div id='language_bar'>
<a style="margin-left:50px" href="./index.php?locale=es_ES">
<img src='<?php echo $config['paths']['images']['lang']?>/es_ES.gif'/>
</a>
<a href="./index.php?locale=en_UK">
<img src='<?php echo $config['paths']['images']['lang']?>/en_UK.gif'/>
</a>
<a href="./index.php?locale=de_DE">
<img src='<?php echo $config['paths']['images']['lang']?>/de_DE.gif'/>
</a>
</div>
And a config file with:
if (isset($_GET['locale'])) {
$locale = $_GET['locale'];
setcookie('locale', $locale, time() + 60 * 60 * 24 * 30);
} else {
if(isset($_COOKIE['locale'])) {
error_log('En _COOKIE');
$locale = $_COOKIE['locale'];
}
else {
$locale = $config['localization']['default_locale'];
setcookie('locale', $locale, time() + 60 * 60 * 24 * 30);
}
}
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
error_log('setlocale->'.setlocale(LC_ALL, "0")." Env ->". getenv("LC_ALL"));
error_log(_("Submit"));
My main page has some divs interacting via jQuery, and reloading in cascade. Sometimes, some of them (randomly) give a default string value.
by default, it is in spanish (es_ES), and after a few clicks forcing div refreshes, some string is printed in english (en_UK original string). And what is more. If I switch to german (de_DE), after a first refresh where I get every string in german, gettext starts to reurn strings in spanish, and after a while, in english.
Note that I added debug lines to php log. They are really interesting:
When things go right:
[Thu May 31 00:28:51 2012] [error] [client ::1] setlocale->es_ES Env ->es_ES
[Thu May 31 00:28:51 2012] [error] [client ::1] Aplicar, referer: xxxxxxxx/index.php
When do not:
[Thu May 31 00:29:45 2012] [error] [client ::1] setlocale->es_ES Env ->es_ES, referer: xxxxxxxxx/index.php
[Thu May 31 00:29:45 2012] [error] [client ::1] Submit, referer: xxxxxxxx/index.php
So I guess it's _() function failing (I'm always using the alias). Just in case, I looped for 10.000 times over the function, and it gave or 10.000 hits or 10.000 mistakes while translating, so it fails for a whole http request, or doesn't.
My apologies for writing so much, but I would really appreciate some help pointing me in the right direction. (This error occurs not just @ my localhost, but also at my online test server)
¿might have anything to do with the fact that I'm setting the locale for every connection?
My online "playground" is:
Linux server8.nixiweb.com 2.6.32-71.29.1.el6.x86_64 #1 SMP Mon Jun 27 19:49:27 BST 2011 x86_64
My server:
Linux filete 3.2.0-24-generic #39-Ubuntu SMP Mon May 21 16:52:17 UTC 2012 x86_64
PHP Version 5.3.10-1ubuntu3.1
Note that both are 64bits