How to work with i18n in PHP and Symfony?
Is there any add-on for Symfony that allows you to work with i18n and files .po and. mo or similar or is it really necessary to implement a solution for this? Ideally I could call the translation in both twig and Controller. If there is what or what would be the options?
1 answers
Symfony itself has a component for internationalization, and XML or YAML files are used for this. You can still read the translation from a database. Take a look at their documentation regarding:
Http://symfony.com/doc/current/book/translation.html
You can use internationalization in both PHP and template files (using Twig). In the first case, after calling the service container internationalization service, it is only translate like this:
$translator->trans('Hi!');
Already in Twig, just use the filter trans
:
{{ "Hi!"|trans }}