M
M
Maxim Medvedev2015-08-26 16:17:55
Internationalization and localization
Maxim Medvedev, 2015-08-26 16:17:55

How to localize templates in twig?

Hello.
I decided to continue to master twig and faced the following task: there is a certain template in which I need, depending on the selected default language in the system or manually selected by the user, to display text in a certain language.
Let's say the template has the following code:

<div class="page-title">
        [некий заголовок]
</div>

and there is a lang folder which will contain translation files like ru.txt, en.txt and so on.
How to correctly implement the substitution of the necessary translations in the template in twig? I looked at the documentation page twig.sensiolabs.org/doc/extensions/i18n.html, but I did not see how translation files are included and work with them. Who knows how to do it right, tell me, or at least an example for some kind of description of the solution to the problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
matperez, 2015-08-26
@matperez

You can make your own extension, define your own extension , define your trans type method in it, and load translations from where you want. And the standard extension loads translations via Gettext . Read about its use in Google .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question