CDO CDO - 1 month ago 15
PHP Question

How to use Gettext (.mo/.po) files with Symfony2?

I want to use

Gettext
for the translation of my website on
Symfony2


In
../Resources/translations/
i have my translations files like that :

translations/en/LC_MESSAGES/en.mo
translations/en/LC_MESSAGES/en.po
translations/fr/LC_MESSAGES/fr.mo
translations/fr/LC_MESSAGES/fr.po
...


I already configured the default local variable with the help of
Symfony2 cookbook
to be french(fr) http://symfony.com/doc/current/book/translation.html#the-locale-and-the-url

When i go to
app_dev.php/fr/hello/test
, my Hello World is in english. There is something else i need to configure?

Already tried this configuration : Configure Translation component in Symfony 2 to use get text

CDO CDO
Answer

After few days of research, I finally found an answer. It's not the one that i was searching for, but it's a very good alternative.

I found this Awesome Bundle : https://github.com/LeaseWeb/LswGettextTranslationBundle

Very easy to put in place, i recommend you to use "routes" to change locales like that :

prefix:   /{_locale}/
    requirements:
        _locale: |fr|en|es|pt #All your locales "shortcuts"

Be sur to configure the Bundle to use locales shortcuts in Lsw/GettextTranslationBundle/Resources/config/config.yml like that :

parameters:
    gettext.locale_shortcuts:
        en: en_US
        fr: fr_FR
        pt: pt_PT
        es: es_ES

For all configurations, use the step by step bundle configurations (easy to use)