Gettext works intermittently

I managed to successfully enable internationalization and the tag {% trans%} in the branch using the following lines:

$language = "..."; $domain = "project"; putenv("LC_MESSAGES=$language"); setlocale(LC_MESSAGES, $language); bindtextdomain($domain, SITE_DIR . "locale"); textdomain($domain); bind_textdomain_codeset($domain, "UTF-8"); 

And the branch template:

 ... {% trans "Translation.Key" %} ... 

Unfortunately, this works randomly. I mean, by continuing to press F5, say, every second or moving between pages, sometimes it switches to the translated line, as it should ("Translation.Key" becomes "Localized value for output"), and sometimes it returns to the output of the string in the tag {% trans%} ("Translation.Key").

Meanwhile, I see no errors in my magazines. What should I check to understand the source of the problem and make it work consistently?

Thanks in advance.

0
source share
2 answers

In my case, the problem was solved by restarting Apache (or php5-fpm when I use nginx on the remote server) every time I make changes to the translation files. Otherwise, gettext works with a glitch, as described in the question.

+1
source

Make sure your Twig Cache is disabled at design time.

0
source

All Articles