how to create multilanguage page in Symfony? In Symfony 1.0, Jobeet tutorial has very good description. But now on symfony.com, i haven’t seen somethings related to translation of page.
In symfony 1.4, echo __(‘text’); is used, but now in Symfony 2 TWIG is used.
how to create multilanguage page in Symfony? In Symfony 1.0, Jobeet tutorial has very
Share
There is a documentation section on this on the Symfony2 website.
You can check it here: Translations
Basically, you have access in the routing to a special attribute named
_localethat is put in your url and will be used to set the locale in the session. Note that using this scheme, the locale value is automatically set into theSessionby Symfony2You can also specify a default
_localevalue in your routes so it is not mandatory to provide the locale in the url.Then, in twig, you use the special transformer
transandtranschoiceto translate messages. Your messages can be a key or an natural language message that is used as the key, usually in english.The locale to translate the message is taken from the session, so changing the locale in the session (via the url or programmaticaly), will change the translation to another thing.
This uses the
translatorservice under the hood.