Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send visitor to different page based on their language settings

Status
Not open for further replies.

richiwatts

Technical User
Jun 21, 2002
180
0
0
GB
Hi,

Does anyone know of a script that checks the user's language settings and then redirects them to a home page that has their language. I have seen this done in PHP but not in ASP.

E.g
All visitors come in at
Script checks user's language settings and if German, user is automaticallly directed to
I need it to work with 4 languages and if the language is not detectable or doesn't match the languages they stay at to select a local site from a map.

The languages I need

en-uk
en-us
de (german)
sv (Swedish

If not, can I use PHP inside a page with .asp extension?

Richi
 
You can do something like this:

Code:
if (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") <> "da") Then
Response.Redirect("myserver/da.asp")
End if


/Adam
 
Sorry, I am a biginner. How would I write this out? Would it go in between <head> </head>

Thanks for your help,
Rich
 
Above everything...

Code:
<%@LANGUAGE="VBSCRIPT">
<%
if (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "da") Then
Response.Redirect("myserver/danish.asp")
Elseif (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "se") Then
Response.Redirect("myserver/swedish.asp")
End if
%>
<html>
<head>
</head>
<body>
</body>
</html>

/Adam
 
Thanks Adam,

For UK and US do I use the following language code??

"en-uk"
"en-us"

Thanks for your help.

Rich
 
Another way is to change your regional settings from control pannel to the country code you want. For example, set your regional settings to Swedish, then create an ASP page with following code and access it from your browser. It will return you the language code.

Code:
<%=Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")%>


/Adam
 
try this:

Code:
<% 

sLanguage = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") 

If InStr(sLanguage, "fr") <> 0 Then
Response.Write "Bonjour"
ElseIf InStr(sLanguage, "es") <> 0 Then
Response.Write "Hola"
Else
Response.Write "Hello"
End If

%>

-DNG
 
I have tried to set this up but am getting an error message:

Code:
<%@LANGUAGE="VBSCRIPT">
<%
if (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "se") Then
Response.Redirect("[URL unfurl="true"]http://www.domain.com/se/home.asp")[/URL]
Elseif (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "de") Then
Response.Redirect("[URL unfurl="true"]http://www.domain.com/de/home.asp")[/URL]
Elseif (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "en-uk") Then
Response.Redirect("[URL unfurl="true"]http://www.domain.com/uk/home.asp")[/URL]
Elseif (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "en-us") Then
Response.Redirect("[URL unfurl="true"]http://www.domain.com/us/home.asp")[/URL]
End if
%>


Error message:

Active Server Pages error 'ASP 0221'

Invalid @ Command directive

/ctek_site/index.asp, line 3

The specified 'if (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "se") Then Response.Redirect("se/home.asp") Elseif (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "de") Then Response.Redirect("de/home.asp") Elseif (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "en-uk") Then Response.Redirect("uk/home.asp") Elseif (Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") = "en-us") Then Response.Redirect("us/home.asp") End if ' option is unknown or invalid.
 
Thanks,

Now I don't get the error message but it doesn't redirect either.

Any ideas?

Rich
 
For redirects within a page, setting:

<%
response.buffer = true
%>

at the top of the page can often make things work more smoothly.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top