HomeASP HostingWeb DesignRegister DomainSupportAbout Us

FAQ
Support :: FAQ


How to detect a visitor’s language settings in ASP
You can detect the language settings of your visitors’ browsers in ASP and I’ll explain how to do that. The information about the language is in an HTTP header variable named HTTP_ACCEPT_LANGUAGE and you can access it from ASP through the Request.ServerVariables collection.

The following ASP code, will display the default language set in your browser, on your screen:

<%

Response.Write "The default browser language is set to: " & Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")

%>

Note that you may have more than one language set as default language in your browser. For example if you are in Canada and you use both English and French, your browser’s language string might look like this: “en-ca,fr-ca”

Why would you want to know what are your visitor’s language settings?

For example you might want to display your website in different languages, depending on the user’s browser language settings. Consider the example below, which will display one and the same greeting in 3 different languages, depending on the user’s language settings:

<%

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


%>
© Copyright 2001-2004 Art Branch Inc.