Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 locale detection and translation

Here is what I'm stuck on. I'm working on Symfony2 and trying to make the translations working. But somehow, I can't make it work as it should. Here's what I got. In the config.yml

translator:      { fallback: de }
session:
        default_locale: en

In messages.en.yml I have this structure:

Please log in: Bitte melden Sie sich an

I also have similar files for messages.en_US.yml, messages.ru.yml, etc.

In the code I use $this->get('session')->setLocale('ru_RU'); to change the locale.

But the translation works only when the locale is set to "en_US" or "de_DE". In any other case it returns the key, not the value. I try the translation with this code

return new Response($this->get('translator')->trans('Please log in').' '.$this->get('session')->getLocale()); and it returns the locale I have set.

So what can cause this problem?

like image 875
ArVan Avatar asked Jan 19 '26 23:01

ArVan


2 Answers

you should clear the cache by using the symfony comand

app/console cache:clear --no-debug

then eventually restore write permission on cache/ and log/ folders as described here

like image 92
svassr Avatar answered Jan 22 '26 13:01

svassr


I found the answer myself. Just needed to clean up the cache for Symfony. Used console to do so. Changed directory to myProject/app and used this commands to clean the cache and logs:

sudo rm -R cache/
sudo rm -R logs/
like image 32
ArVan Avatar answered Jan 22 '26 14:01

ArVan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!