Template localization in symfony2

Some languages, such as Persian (Farsi), have a structure from right to left.

To fully execute i18n and l10n, I have to translate the lines and flip the layout.

I am translating strings using the complete translation component.

Now I'm trying to flip the layout. How to load rtl version of rtl based loacle in twig file in symfony project?

+4
source share
1 answer

In other words, you want to load the right CSS file according to your locale.

Twig lets you handle this seamlessly. Here is an example of how you can do this,

First create a global template app/Resources/views/base.twig.html containing

 {% block head %} {% block direction %} <HTML> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> {% endblock %} <head> <!-- put here your head meta data --> {% endblock %} 

Then you can add a version of your base template in English and Persian (or any other language)

application / resources / views / base.en.html.twig

 {% extends '::base.html.twig' %} 

In the Persian version of your base template, and since you need RTL for html and custom CSS, you need to install more details about this,

app / Resources / views / base.fa.html.twig (I think "fa" is the language code for the Persian language)

 {% extends '::base.html.twig' %} {% block direction %} <HTML DIR="RTL"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> {% endblock %} {% block stylesheet %} {{ parent() }} <!-- Add here your specified stylesheets --> {% endblock %} 

Then, using a three-tier membership, you can inherit from the right base template according to your locale. Here, what your layout should contain,

 {% extends '::base.' ~ app.request.locale ~ '.html.twig' %} 
+7
source

Source: https://habr.com/ru/post/1444081/


All Articles