qTranslate for Wordpress不会自动为我提供正确的语言 [英] qTranslate for Wordpress doesn't automatic give me the correct language

查看:114
本文介绍了qTranslate for Wordpress不会自动为我提供正确的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用qTranslate for Wordpress将博客文章用英语,瑞典语和德语撰写.我已激活检测浏览器语言",以便将访问者转发到其浏览器指定语言的正确URL.

I use qTranslate for Wordpress to have my blog posts in English, Swedish and German. I have activated the "Detect Browser Language" so that the visitor will be forwarded to the correct URL for the language specified by his browser.

因此,如果我访问blog.domain.com,那么我将被转移到blog.domain.com/sv/,并且我的博客文章都是瑞典文,那就太好了!但是现在问题出了,如果我第二次从同一台计算机再次访问blog.domain.com,我就不会被转移,并且博客文章的默认语言是英语.

So if I visit blog.domain.com I get transfered to blog.domain.com/sv/ and my blog posts is in Swedish, that is great! But now to the problem, if I visit blog.domain.com again a second time from the same computer I don't get transfered and the blog post is in default language English.

我在这里做错什么了吗?似乎很奇怪,我总是需要指定语言,我需要它根据浏览器是自动的.

Is there something I'm doing wrong here? Seems strange that I always need to specify the language, I need it to be automatic based on the browser.

推荐答案

我发现了一个不错的.htaccess规则,可以在此处设置lang cookie:

I found a nice .htaccess rule that can set the lang cookie here: http://tips.naivist.net/2012/11/09/remembering-the-user-language-choice/

似乎更容易并且可以正常工作:

It seems easier and works just fine:

只需更改您的主.htaccess即可:

Just alter your main .htaccess to this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Language Cookie redirect
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteCond %{HTTP_COOKIE} lang=(lang1|lang2) [NC] 
RewriteRule ^(.*)$ /%1/ [R=302,L]

RewriteCond %{REQUEST_URI} ^/(lang1|lang2)/.*$ [NC] 
RewriteCond %{HTTP_COOKIE} !lang=%1 [NC] 
RewriteRule . - [cookie=lang:%1:.%{HTTP_HOST}:144000:/]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

lang1 lang2 中,您可以在网站中插入要翻译的语言.

In lang1 and lang2, you can insert the languages you have translation in your site.

这篇关于qTranslate for Wordpress不会自动为我提供正确的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆