I am creating a site in Wordpress,It is basically an english site but when user clicks on translate it translate it into Arabic.There is problem of ltr
and rtl
,How can I solve that.I am using qtranslate plugin right now.Same is the case with urdu ,kurdish languages.
Anyone who can help me with this
please see attached image
Thanks

- 22,600
- 28
- 79
- 90
-
@SergeyS My site doesn't appear fine when I click on arabic,there are issues with rtl and ltr ,how can i handle that.?I can handle the words and add words in the .po file – Dec 24 '12 at 19:44
-
You're going to have to be a lot more specific. What sort of directionality problems? column order? Character order? Latin/punctuation dancing with Arabic? – bmargulies Dec 24 '12 at 19:46
-
@bmargulies arabic is not rtl – Dec 24 '12 at 20:09
-
It would be very helpful if you could add a screenshot or something. – Auxiliary Dec 24 '12 at 20:13
-
@Auxiliary please have a look – Dec 24 '12 at 20:18
-
@user1765876 Arabic is not RTL? I think you don't know Arabic language. – Arash Milani Dec 24 '12 at 20:22
-
do you add `dir='rtl'` to the `html` tag for `rtl` languages? or at least to the parent of all translated text – bart s Dec 24 '12 at 20:25
-
@user1765876 is this website live? the plugin should be inserting some info about the language in the html. so we can use that to style the elements in css – Arash Milani Dec 24 '12 at 20:25
-
@ArashMilani I thought the same thing at first, but I think he means that the Arabic is not shown as RTL in his website. – Auxiliary Dec 24 '12 at 20:32
-
@Auxiliary yes I mean the same,yes the website is live,I amusing qtranslate plugin,I dont know where to write the dir=rtl,can you help me? – Dec 24 '12 at 20:40
-
@barts where to add this line?I am using plugin – Dec 24 '12 at 20:40
-
@user1765876 when you click something to do the translation, add some code to add `dir='rtl'` to the html tag ``. See answers below – bart s Dec 24 '12 at 20:49
-
you can have your style_rtl.css switched with `qtrans_getLanguage()` check. – Lenin Jan 23 '13 at 07:35
-
You can see my answered posts or Questions (I posted and provided answers) for your solution on this qTranslate. – Lenin Jan 23 '13 at 07:36
2 Answers
It seems this wordpress plugin is inserting a language direction and name into the <html>
tag. like this:
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
OR
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="ar-AR">
If I understand you the plugin is not rendering correct direction
attribute for the ltr
languages.
First Option
One option is to use javascript to fix this. simply we detect the rtl
languages by their ISO codes (here it's ar
for Arabic) and adding a class to the body
tag
jQuery(function(){
jQuery("html[lang=ar]").attr("dir", "rtl")
.find("body").addClass("right-to-left");
});
Now you can style that elements in the theme css file by prefixing that right-to-left
class like this: (this is just a sample)
body.right-to-left my-element li {
float:right;
direction: rtl;
}
.
Second Option
As suggested by the other answer Use php to insert that class name into the body
tag of the page. open your header.php
file in your theme and edit this line:
<body class=" <?php if($_GET["lang"] == "ar") echo "right-to-left"; ?> ">
Now use the same css to style you elements

- 6,149
- 2
- 41
- 47
-
-
It might be in different locations according to your theme. find which file has the `` start tag. and apply that change to that file. – Arash Milani Dec 25 '12 at 11:19
-
One simple but inefficient way is to check the language with PHP in your theme's header file and if it's Arabic or another RTL language you can add the dir="rtl" to your HTML or any tag you want. I realized that qTranslate has a GET method mode and adds something like ?lang=ar
to the URLs. So you could easily check it with PHP: if ($_GET["lang"]=='ar') ...
EDIT
You can add something like this in your theme's header file. (You can find this file from path_to_wordpress/wp-content/themes/your_theme/header.php), It's either called header.php or something similar.
find the <body>
tag and add this line to the end (before the > sign):
<?php if($_GET["lang"] == "ar") echo "dir='rtl'"; ?>

- 2,687
- 5
- 37
- 59
-
qtranslate doesn't forward anything with URL in "lang",i mean there is no name value pair – Dec 24 '12 at 20:58
-
qTranslate has 3 modes, one of them is the URL mode. See http://www.qianqin.de/qtranslate/ – Auxiliary Dec 24 '12 at 21:02
-