双语wordpress:如何更好地切换语言?

双语wordpress:如何更好地切换语言?

问题描述:

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:

  1. 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.
  2. I want to keep the url like domain.com/ar/someslugsoranything and domain.com/en/someslugsoranything.
  3. 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'];

我有两个网站以英文和阿拉伯文版本显示。 p>

环顾四周之后,我发现qTranslate插件可以很好地解决一个简单的解决方案。 p>

我使用 .htaccess code>,如下所示: p>

 &lt; IfModule mod_rewrite.c&gt; 
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] 
&lt; / IfModule&gt; 
  code>  pre> 
 
 

主题 functions.php code>以下用于检测语言: p>

  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'])&amp;&amp;!isset($ _ SESSION ['custom_lang'])){
 $ _SESSION ['custom_lang'] =“en”; 
} 
 $ GLOBALS ['  q_config'] ['language'] = $ _SESSION ['custom_lang']; 
返回$ vars; 
} 
 
 add_filter(“query_vars”,“inspectVars”); 
  code>  pre  > 
 
 

此会话设置我用于切换RTL / LTR样式表。 有没有更好的方法呢? p>

现在,我面临的问题是: p>

  1. 我如何使用 将当前页面,博客切换成其他语言的链接? 我使用domain / ar和domain / en进行切换,但首先需要回家。 li>
  2. 我想保留网址,如 domain.com/ar/someslugsoranything code>和 domain.com/en/someslugsoranything code>。 li>
  3. 我有一些图片,模板上的幻灯片需要随语言变化而切换。 最好的方法是什么? 还有HTML格式文本,也需要切换。 li> ol>

    编辑: 我后来注释掉了以下内容,因为启用qTranslate自己的语言切换器会保留 选择语言的持久性。 实际上整个 inspectVars code>函数都可以省略。 p>

      $ GLOBALS ['q_config'] ['language'] = $ _SESSION ['custom_lang'  ]; 
      code>  pre> 
      div>

I have solved most of the problems.

By commenting out the two lines of .htaccess file:

#RewriteRule ^ar[\/]?$ index.php?lang=ar
#RewriteRule ^en[\/]?$ index.php?lang=en 

And many of the problems got resolved with the following post I found just now:

Displaying content based on language with qTranslate Biggest problem I have now is the mixed HTML texts which need to be switched in Arabic. Within the template I tried qTranslate shortcodes and the <!--:lang--><!--:--> tags but they do not work there. Also, writing arabic directly into HTML is not a good idea I guess.