5

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, 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

ARemesal
  • 2,923
  • 5
  • 24
  • 23
  • 1
    I've found out that, restarting Apache (full restart: /etc/init.d/apache2 restart), it comes back to work fine, but I can't accept this as a solution when I go to production environment... any ideas? – ARemesal Sep 10 '10 at 11:26

4 Answers4

1

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

Kemal
  • 2,602
  • 1
  • 21
  • 14
0

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
Community
  • 1
  • 1
Carlton
  • 5,533
  • 4
  • 54
  • 73
0

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.

Paul DelRe
  • 4,003
  • 1
  • 24
  • 26
xgretsch
  • 1,294
  • 13
  • 15
0

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.

Evgeny Tryastsin
  • 723
  • 2
  • 10
  • 19