Reputation: 146563
I have a working gettext installation in a PHP-powered web site (PHP/5.3 running as Apache module on Windows). The problem is that certain arbitrary strings do not get translated. A few texts (less than 1% and always the same) remain in the original language. The crazy bit is the details:
Surrounding strings do get translated:
Line 95: <th><?php echo _('Address'); ?></th> <-- Translated -->
Line 96: <th><?php echo _('Number'); ?></th> <-- Not translated!!! -->
Line 97: <th><?php echo _('City'); ?></th> <-- Translated -->
Any idea or hypothesis?
Upvotes: 1
Views: 283
Reputation: 146563
The gettext library depends on locale information transmitted in environment variables. That's extremely unreliable on the Apache mod_php SAPI (aka "PHP as Apache module") on Windows because a single thread will typically be shared by different scripts.
In my case, I was running http://parent.example.com
which made an internal HTTP post request (with Curl) to http://child.example.com
and then composed and printed the results. It happens that both sites are hosted on the same site so both scripts shared environment and I was getting this sequence:
I was able to diagnose this using the Process Monitor utility. I captured data while doing a page load and then filtered by "path ends with .mo
". That revealed that Apache was loading an unexpected catalogue in addition to the right one.
As quick & dirty workaround I'm calling bindtextdomain()
and textdomain()
again right after curl_exec()
. (In the long term I'll have to migrate to FastCGI, use a pure PHP gettext library or convince the client to switch to Linux, whatever's easier.)
Upvotes: 2