doudou348131346 2012-12-04 17:31
浏览 36
已采纳

双语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'];
  • 写回答

1条回答 默认 最新

  • doujieju0397 2012-12-04 19:11
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog