Forum Moderators: coopster

Message Too Old, No Replies

gettext doesn't work properly

Occasionally translate string

         

akademik

11:37 am on Apr 24, 2010 (gmt 0)

10+ Year Member



Hello,

I have big problem and don't know what's wrong...

I'm using gettext in order to translate strings on the page.

$language = 'de_DE';
//putenv('LC_ALL='.$language);
setlocale(LC_ALL, $language);

$domain = 'messages';
bindtextdomain($domain, "./locale");
textdomain($domain);


echo _("Hello World!")


This works but after five refresh page will show original (english) strings. Further, after next five refresh translations is visible again, and so on...

What can be the problem here?

Slackware, lighttpd, PHP5

akademik

11:36 pm on Apr 25, 2010 (gmt 0)

10+ Year Member



Never mind, server admin made some changes and it works now...

But there is new problem now...

If I update new .mo file with new translated strings, I only get blank page after refresh. Seems that situation normalize after few attempts and than it works normal...
With Tamper Data I can see that request is OK 200, but content length is 0, like the server does not send anything to browser...

How would I overcome this problem?

coopster

2:43 pm on Apr 26, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



200, or 304 (Not Modified)? I can see 304 and zero-length, but 200? Are you handling the response yourself in a script? If so then perhaps the logic is the failure point.

akademik

3:39 pm on Apr 26, 2010 (gmt 0)

10+ Year Member



Thanks for your response...

It is definitely OK - 200. This is just test script to se if gettext will work on the server. There is not any handling script... here is c/p:

$lang = 'de_DE';

putenv("LANGUAGE=$lang");
setlocale(LC_MESSAGES, '$lang');

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

echo _("Hello World!");

Just to mention, error log does not catch anything in this moment, like there is no error at all. There must be something that generates this behavior, but where to look at? :)

coopster

3:44 pm on Apr 26, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Turn up your error_reporting if you haven't already. Also, this is not going to parse when used in single quotes ...
setlocale(LC_MESSAGES, '$lang');

akademik

3:50 pm on Apr 26, 2010 (gmt 0)

10+ Year Member



Yea, actually it was nearly copy paste :)
Of course, it is done properly on the server, without quotes, so that is not the problem.

akademik

3:54 pm on Apr 26, 2010 (gmt 0)

10+ Year Member



Addition to last post:

error_logging is on so every error, warning, notice is logged, but as mentioned before, nothig there to see about this...

akademik

4:07 pm on Apr 26, 2010 (gmt 0)

10+ Year Member



I don't know if this is important but I'm usin poedit under on my XP and than upload newly generated .mo file over the old one.

coopster

4:12 pm on Apr 26, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Understood. Everything looks OK. Why did you switch to LC_MESSAGES rather than LC_ALL? Here nor there.

lighttpd will cache as much as possible. I'm guessing that may be the issue, not PHP. Like I said though, I'm just guessing. Try adding something different to your Hello World test, like milliseconds() or something. Hopefully lighttpd won't think this should come from the cache. Also, maybe that is why you are getting 200 OK with zero content.

Once again, I'm just brainstorming here. Your PHP looks fine to me. It could be setlocale() but I highly doubt it.

coopster

4:15 pm on Apr 26, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Is poedit saving carriage returns and line feeds in your .mo file? What I'm getting at is to be certain you are saving with the correct line endings. And if you are saving as UTF-8 watch out for the byte order mark.

akademik

4:28 pm on Apr 26, 2010 (gmt 0)

10+ Year Member



I've tried with milliseconds, same again... I've switched to LC_MESSAGES just to try, but it seems that both messages and LC_ALL works. I don't know which one to use. Actually, everything works ok excepts that issue after replacing mo file.

Poedit is set to use Unix line endings , everything is translated with utf8 encoding, same as online page.

It must be something about caching...

I hate this kind of problems, when I dont know where to look.

akademik

5:10 pm on Apr 26, 2010 (gmt 0)

10+ Year Member



I found workaround for now...

Just changed domain from 'messages' to something else and problem disappears. And every time I have to upload new .mo file I will have to change domain to some new string.

It's dirty trick I know but I don't see any other solution right now.

coopster

5:23 pm on Apr 26, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yeah, and that certainly sounds like a cache issue. Which version of PHP5, by the way?

akademik

5:29 pm on Apr 26, 2010 (gmt 0)

10+ Year Member



PHP 5.2.9