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.
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.
I had the same problem and I have modified the qTranslate to add this functionality. What I did was to save a cookie with the language info, this cookie is saved when the user clicks on the language’s flag in the widget.
My logic is the following:
So few steps:
Modify qtranslate_core.php file:
Modify file qtranslate_widget.php (to add the ‘save_lang’ param to each’s language URL):
Every time you see this line:
replace it with:
And then add that function:
I hope this helps 🙂
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:
Just alter your main .htaccess to this:
In lang1 and lang2, you can insert the languages you have translation in your site.
Difficult to point out what might be wrong with the above description
The possible error might be when you login first you are taking the input from “Detect Browser Language”. And from next time retrieving it from a cookie. There might be something that’s gone wrong with this process. Or you might not be using cookies at all.
You can save the user’s language preset if you have a login database.
Then change the url according to the desired language soon as they login.