开发者

Gettext (i18n) and Smarty running erraticly

I'm developing a webapp with PHP and Smarty. I use gettext to internationalize, but I've a problem: it only works sometimes, absolutly randomly. I load a locale ('de_DE', by example) with putenv+setlocale+bindtextdomain+textdomain,开发者_如何学Python reload the page, and see "Search"; reload again and I see "Suche"; two more reloads and get "Suche" but thirth give me "Search" again, then I see "Search" many time and suddenly I can see "Suche" again... randomly.

I've deactivated cache for Smarty, but same issue. I've configured Smarty to use different directories for different languages, templates_c/en_GB, templates_c/de_DE, and so on. Compiling works fine that manner.

I'm using smarty-gettext for templates translation.

Are there any known issue about using gettext and Smarty?

Edit to add some information: I'm running my tests in a Linux machine:

apache2 2.2.14

gettext 0.17

php 5.3.2

smarty 3-SVN$Rev: 3286


Do you have Xcache or any other opcode cacher installed/enabled? Try disabling them.


I'm experiencing the same issue - sometimes the page shows the translation, and sometimes it doesn't.

But I'm using vanilla PHP (no Smarty), and running on Mac OS X (not Linux).

My code looks like:

$locale='fr_FR'; //...for example...
putenv("LC_ALL=$locale");
setlocale(LC_ALL,$locale);
bindtextdomain("messages","./locale");
bind_textdomain_codeset("messages","UTF-8");
textdomain("messages");

Currently trying to hunt the problem down - I will let you know if I succeed.


Used to get similar problem while using locale "pt_BR" when actually using russian words. Solved this by setting locale to "ru_RU". Hope this might help.

This is my configuration that actually worked:

$directory = './locale';
$domain = 'smartybook';
$locale ="ru_RU";
setlocale(LC_ALL, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');

One more important note: started working only after using msgfmt -c -v -o msgfmt -o wasn't enough. Also important: need to be root when issuing formatting commands, also don't forget to restart apache.


I had a similar intermittent problem PHP gettext and vagrant running ubuntu

Try one of the following, I think it will depend how you have PHP running with Apache

sudo service php5-fpm restart

sudo service apache2 restart
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜