Redirect in language folders based on browser language preference

This is a place to discuss how to adapt mojoPortal to the needs of different cultures. Before asking questions here please first review the localization documentation.

This thread is closed to new posts. You must sign in to post in the forums.
7/16/2010 2:10:02 PM
Gravatar
Total Posts 18

Redirect in language folders based on browser language preference

Hi Joe,
hi everybody,

first of all thanks for the great system. It works for us reliable and fast since long time now.

We have successfully set up the folders for different language (www.domain.com/en etc.).

Is there a way to redirect the user to the language-folder based on the browser-language-setting when the user comes to www.domain.com?

 

Thanks

Klaus

7/16/2010 2:46:08 PM
Gravatar
Total Posts 550

Re: Redirect in language folders based on browser language preference

Hi Klaus,

The browser-language-setting not a good condition to recognize what site user want to visit. I think the best solution is you allow visitors select a site(language for site) by add a site selector (language selector) like what you see on top of this site.

Hope Helps,

Asad

7/16/2010 2:54:21 PM
Gravatar
Total Posts 18

Re: Redirect in language folders based on browser language preference

Hi Asad,

yes, that it what we are doing; but I thought it would be nice to land on a page with the "home"-language even when you navigate to the base-site www.domain.com.

Thanks to your fast reply.

 

Klaus

7/17/2010 8:33:36 AM
Gravatar
Total Posts 18439

Re: Redirect in language folders based on browser language preference

I agree with Asad, it can be dodgy making assumptions based on the user's browser language preference. Some sites do this kind of thing and it is possible to implement it in a custom UserControl that you would include in your layout.master, but it would require a good bit of thought to avoid problems. You want the user to feel in control at all times and avoid unexpected experiences.

For example you would only want to do the redirect on the first request and only if the request is for your home page. So you would want to set a cookie before you redirect so that on the next request you can detect the cookie and know that you already redirect one time so don't redirect again if the user comes back to your main language site. There could be problems if the user's browser does not accept cookies then you would end up redirecting on every request. Of course you would have to decide also based on whether you have a site created for the user's language and also consider that the browser language can be an array of languages, probably the lowest index is the most preferred language. You would need to be careful to avoid errors if the language cannot be detected. There are lots of bots and spiders that may not indicate a language.

Best,

Joe

3/3/2012 10:40:13 AM
Gravatar
Total Posts 14

Re: Redirect in language folders based on browser language preference

Hi Joe, Asad, Klaus,

I understand and I can follow Klaus' arguments, hence you are doing the same for the Admin Menu selection of the Mojoportal or do I miss something?

I actually have the same request and I tried to find a solution which does not touch the mojoportal in it's details.

I basically followed your suggestions re related sites.

I also added a language selection menu so the user can manually switch from one language to another.

Then I did as follows:

1) added a new file to the www-root, called default-init.aspx (just the very top site) with content as follows:

*********************************************************************************

<%@ Page Language="VB" %>
<%
Dim strLanguage,strRedirect, strHost
strHost  = lcase(Request.ServerVariables("SERVER_NAME"))
strLanguage = lCase(Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")).substring(0,2)

Select Case strLanguage
Case "de"
 strRedirect = "/ge"
Case Else
 strRedirect = ""
End Select

Response.Redirect("http://" & strHost & strRedirect & "/default.aspx")
%>

 

*********************************************************************************

2) I changed in IIS the default document to be "default-init.aspx"

This way the browser selected language is being used to place the user to the language related site.

Nevertheless, the user has still the choice to change the language on the site itself if he wishes.

HTH

Juerg

You must sign in to post in the forums. This thread is closed to new posts.