Redirecting to respective language versions and browser lang

General Discussion about the commercial Enuuk Auction Platform
Post Reply
bamse
Posts: 220
Joined: Mon Feb 06, 2012 12:05 pm
Contact:

Redirecting to respective language versions and browser lang

Post by bamse » Wed Jan 30, 2013 2:36 pm

As far as I understand, phpauction handles multiple languages through a cookie which is set if one requests a URL like: www.example.com?lang=de_DE (for German).

Haven't tried yet, but I believe I could use mod_rewrite to redirect requests to www.example.de to www.example.com?lang=de_DE as a 301 redirect.

Now something else I was wondering is how to make the site sensitive to the user's preferred language setting (in the browser). All the tutorials I found were for sites where different language versions are stored in subdomains or sub-directories. Is there an elegant way to make it work for the language cookie as well?

RWAP
Site Admin
Posts: 750
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Redirecting to respective language versions and browser

Post by RWAP » Wed Jan 30, 2013 3:32 pm

Yes, you could use a 301 redirect in .htaccess to change this over from www.example.de and it should work fine.

As for using the language set in the user's browser, the code to look at is in Core/Action.php

Code: Select all

            //Set the language, present in "langCookie" cookie or "lang" user input
            if(isset($parameters['lang'])){
                $this->context->language = $parameters['lang'];
            }elseif(isset($parameters['langCookie'])){
                $this->context->language = $parameters['langCookie'];
            }else{ //if nothing, use default language as the current language
                $this->context->language = $this->context->siteOptions['defaultLanguage'];
            }
I would recommend adding a function to test the value of $_SERVER['HTTP_ACCEPT_LANGUAGE'] against supported languages on the server, and then add a second elseif clause which uses this setting if the passed browser language is supported.

bamse
Posts: 220
Joined: Mon Feb 06, 2012 12:05 pm
Contact:

Re: Redirecting to respective language versions and browser

Post by bamse » Fri Feb 01, 2013 11:46 pm

Thanks for the reply. I implemented the domain rewrite and it works.

Will look into the second part, but still need to decide on what to give priority. E.g. if somebody with main language set to Welsh is accessing www.example.de, should they be shown the German or the Welsh version of the website?

RWAP
Site Admin
Posts: 750
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Redirecting to respective language versions and browser

Post by RWAP » Sat Feb 02, 2013 9:01 am

There are two problems here.

a) The 301 redirect should use a different parameter to lang=DE - as otherwise surely the user cannot overwrite the default language

b) As to order of priority - I should think that this should be:

- Any cookie on the user's browser
- The value of the lang parameter
- The value of the parameter set by the 301 redirect
- The language used in the user's browser (if supported)
- The default Language

The reason why the browser language should be given a low priority is two-fold:
1) The user could be on holiday and using someone else's computer.
2) I should imagine that if most people went to www.example.de - they would expect the content to be in German.

So long as the ability to change the language is clearly set, then that is not so much of an issue.

Could you share your code on here?

bamse
Posts: 220
Joined: Mon Feb 06, 2012 12:05 pm
Contact:

Re: Redirecting to respective language versions and browser

Post by bamse » Sun Feb 03, 2013 2:26 pm

Not sure what you mean in "a)". Do you mean the following issue/problem: somebody is accessing example.de, gets redirected to example.com and the lang_cookie set to de_DE. User realizes they prefer the English version, click on "English", lang_cookie gets set to en_EN. User leaves page. User comes back to example.de, expecting to get the English version (which he/she set last time), but instead gets redirected to the German version again.

In "b)" I am not sure what you mean by "any cookie on the user's browser".

Other than that I agree with what you wrote on priorities.

Will share the code, when I get around doing this. So far I only have the following rewrite rules to share:

Code: Select all

 
          RewriteCond %{HTTP_HOST} ^example.de [NC,OR]
          RewriteCond %{HTTP_HOST} ^www.example.de [NC]
          RewriteRule (.*) http://www.example.com/$1?lang=de_DE [R=301,L]
(This also rewrites folders such as www.example.de/user/register.)

Actually the idea of all this for us is not that actual users are accessing example.de, but rather to get a slightly better google page rank in Germany or just to make our customers happy that we also have a .de domain. Not sure whether this has any effect on page rank, also since I read somewhere that ugly URL including things like ?lang=de are not popular with search engines.

RWAP
Site Admin
Posts: 750
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Redirecting to respective language versions and browser

Post by RWAP » Mon Feb 04, 2013 10:44 am

bamse wrote:Not sure what you mean in "a)". Do you mean the following issue/problem: somebody is accessing example.de, gets redirected to example.com and the lang_cookie set to de_DE. User realizes they prefer the English version, click on "English", lang_cookie gets set to en_EN. User leaves page. User comes back to example.de, expecting to get the English version (which he/she set last time), but instead gets redirected to the German version again.
Yes exactly - if the user clicks on www.example.de?lang=en_US does this still work with the 301 redirect - surely it then becomes:

www.example.com?lang=en_US?lang=de_DE

Actually, your 301 code is also slightly problematic, if the user clicks on a search link to:

www.example.de?keyword=test

Surely this becomes

www.example.com?keyword=test?lang=de_DE

So whilst the keyword will be set, the language may not be changed?

In "b)" I am not sure what you mean by "any cookie on the user's browser".
When the initial parameter is passed to the Enuuk code, Enuuk sets a cookie to remember the language - that is all I meant.
Actually the idea of all this for us is not that actual users are accessing example.de, but rather to get a slightly better google page rank in Germany or just to make our customers happy that we also have a .de domain. Not sure whether this has any effect on page rank, also since I read somewhere that ugly URL including things like ?lang=de are not popular with search engines.
This would probably only help page rank if some of the listings are in German also - as we all know, with SEO it is more a matter of trying and waiting to see what happens!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest