Processing LTR and RTL for Arab sites (internationalization)

I create a website in Wordpress. This is mainly an English site, but when a user clicks on a translation, he translates it into Arabic. There is a problem with ltr and rtl . How can I solve this problem. I am using the qtranslate plugin right now. The same thing happens with Urdu, Kurdish. Anyone who can help me see the attached image. enter image description here Thanks

+4
source share
2 answers

This wordpress plugin seems to be inserting the language direction and name into the <html> . eg:

 <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 that the plugin does not return the correct direction attribute for ltr languages.

First option

One option is to use javascript to fix this. we just discover rtl languages ​​by their ISO-codes (here it is 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 these elements in the theme css file, indicating that the right-to-left class looks like this: (this is just a sample)

 body.right-to-left my-element li { float:right; direction: rtl; } 

.

Second option

As suggested by another answer. Use php to insert this class name in 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 for element styles

+2
source

One simple but ineffective way is to check the language with PHP in the theme header file, and if it's Arabic or another RTL language, you can add dir = "rtl" to your HTML or whatever tag you want. I realized that qTranslate has GET mode and adds something like ?lang=ar to the urls. This way you can easily check it with PHP: if ($_GET["lang"]=='ar') ...

EDIT

You can add something like this to the theme file header. (You can find this file from path_to_wordpress / wp-content / themes / your_theme / header.php), or it is called header.php , or something like that.

find the <body> and add this line to the end (before the sign ):

 <?php if($_GET["lang"] == "ar") echo "dir='rtl'"; ?> 
+1
source

All Articles