1
votes

Some time ago, I started translating the Symfony 2.1 website I'm working on, using the "correct way" through /{ _locale } in the URL. Now the translation worked fine for most routes, but some of them (/login, /register, ...) kept coming in the default language (fr in this instance), because they didn't have the { _locale } part in their url.

Through the debug panel I realised that the locale was not actually changed through url navigation (unlike this had me believe).

So I then went there, where I found information and link to set up a listener in order to change the session locale in function of the path that is called. All defaults locale declarations (both in config.yml and the listener itself) are "fr".

When I switch languages, I can actually see on the debug panel that the session locale changes. However, it would appear that the translation has somehow been broken : every translation bit is made in english, even though the default language is french, and despite the session locale being "fr".

Where could that come from? How can I fix it?

Thanks in advance.

More technical information:

routing.yml:

AuraeLCUserBundle:
    resource: "@AuraeLCUserBundle/Resources/config/routing.yml"
    prefix: /{_locale}/
    defaults: { _locale: fr }
    requirements:
        _locale: en|fr

a twig example:

<p>{{ 'layout.greeting.welcome'|trans({}, 'AuraeLCUserBundle') }}</p>
1

1 Answers

0
votes

3 things here are critical. default lang (setted in config) and if your using translatable doctrine extension:

# app/config/config.yml
framework:
    session:          { default_locale: 'fr_FR' }
    translator:       { fallback: 'en' }
.....

stof_doctrine_extensions:
    default_locale: 'fr_FR'

They must be different because of circular reference exception appears when the default locale won't go.

Translator is looking for files yaml|xml|gettext with sufix fr_FR ex:

messages.fr_FR.yml
messages.en.yml
yourcatalogue.fr_FR.yml
yourcatalogue.en.yml

Read this for more details:

Change default locale in Symfony2

http://symfony.com/doc/2.0/book/translation.html

http://0hlsson.se/2011/07/27/symfony2-and-translatable-example/