Drupal - how to load RTL style in RTL language
Drupal 8 uses libraries, and you can load these in templates. One way of achieving language direction dependant libraries would be to use the html_attributes['dir']
variable in html.html.twig
and load different libraries depending on the value:
{% if html_attributes['dir'] == 'ltr' %}
{{ attach_library('your_theme_name/styles') }}
{% elseif html_attributes['dir'] == 'rtl' %}
{{ attach_library('your_theme_name/styles_rtl') }}
{%- endif -%}
Set up a couple of libraries:
styles:
version: 8.x-1.0
css:
theme:
css/styles.css: {}
styles_rtl:
version: 8.x-1.0
css:
theme:
css/styles-rtl.css: {}