WordPress theme won’t switch to RTL using qTranslate plugin

I am using qTranslate plugin which allows me to translate posts and fields.

The first language is English, the second language is Arabic which requires RTL design.

Read More

I followed their FAQ and WordPress’ Right-to-Left Language Support.
The FAQ of the plugin says it should work automatically but if it doesn’t that I need to check WordPress’ documentation on the issue, so I did, it says this:

Start with your main theme stylesheet (usually style.css). Save this
file as rtl.css Add the following attributes to the body selector:

direction: rtl;
unicode-bidi: embed;

So I created a new copy of style.css and named it rtl.css then added direction:rtl to the body selector.

But it’s not working, when I switch the language to Arabic, it still displays LTR.

However if I add direction:rtl to the body selection in style.css it works, the theme switches to RTL.

What can I do in this situation?

Related posts

Leave a Reply

2 comments

  1. The only way I managed to get this to work is by creating a new class in my css called direction and included it whenever the language was Arabic, by doing this

    $currentLang = qtrans_getLanguage();
    if($currentLang == 'ar') {
        // do something
    }
    
  2. In case you need to redirect browse view to read from RTL and by using qtranslate-x plugin, add code below at header.php

    <?php
    $dir_ar = 'dir="rtl"';
    ?>
    <html <?php language_attributes(); ?> <?php if(qtranxf_getLanguage() == 'ar') echo $dir_ar; ?>>
    

    then at function.php, use wp_enqueue_style, wp_style_add_data, to detrmine which stylesheet you need to read as rtl

    wp_enqueue_style('theme-style', get_stylesheet_uri() );
    wp_style_add_data('theme-style', 'rtl', 'replace' );
    

    reference link:
    https://codex.wordpress.org/Right-to-Left_Language_Support
    http://princessdesign.net/wpsnippets/qtranslate/