I have two websites to be displayed in English and Arabic versions.
After looking around I found that qTranslate plugin does the job very good for a simple solutions.
I used .htaccess
as the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^ar[\/]?$ index.php?lang=ar
RewriteRule ^en[\/]?$ index.php?lang=en
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
And at theme functions.php
the following for detecting language:
function inspectVars($vars) {
session_start();
if ($_GET['lang'] == "ar") {
$_SESSION['custom_lang'] = "ar";
} elseif ($_GET['lang'] == "en") {
$_SESSION['custom_lang'] = "en";
} elseif (!isset($_GET['lang']) && !isset($_SESSION['custom_lang'])) {
$_SESSION['custom_lang'] = "en";
}
$GLOBALS['q_config']['language']= $_SESSION['custom_lang'];
return $vars;
}
add_filter("query_vars", "inspectVars");
This session setting I used for switching the RTL/LTR stylesheets. Is there a better way to do so?
Now, the problem I am facing is:
- How do I use a link which would switch current page, blogs into other language? I used domain/ar and domain/en for switching but that takes to home first.
- I want to keep the url like
domain.com/ar/someslugsoranything
anddomain.com/en/someslugsoranything
. - I have some images, slides at the template which need to be switched with the language change. What is best way? Also there's HTML format texts with them, which also needs to be switched.
Edit:
I have later commented out the following because enabling qTranslate's own language switcher keeps the persistence of language chosen. In fact the whole inspectVars
functions can be omitted.
$GLOBALS['q_config']['language']= $_SESSION['custom_lang'];