Redirect based on language

javascript auto redirect based on language

Chinese (China) = zh-cn 

Chinese (Hong Kong SAR) = zh-hk 

Chinese (Macau SAR) = zh-mo 

Chinese (Singapore) = zh-sg 

Chinese (Taiwan) = zh-tw 

Chinese = zh

English (Australia) = en-au 

English (Belize) = en-bz 

English (Canada) = en-ca 

English (Caribbean) = en 

English (Ireland) = en-ie 

English (Jamaica) = en-jm 

English (New Zealand) = en-nz 

English (Philippines) = en-ph 

English (South Africa) = en-za 

English (Trinidad) = en-tt 

English (United Kingdom) = en-gb 

English (United States) = en-us 

English (Zimbabwe) = en-zw 

English = en

This javascript is used to detect a visitor's language in his/her browser and redirect to the page of your choice. It also has a default page.

Language abbreviations for browsers

Here is the script:

Code:<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
if (navigator.appName == 'Netscape')
var language = navigator.language;
var language = navigator.browserLanguage;
if (language.indexOf('en') > -1) document.location.href = 'english.html';
else if (language.indexOf('de') > -1) document.location.href = 'german.html';
else if (language.indexOf('it') > -1) document.location.href = 'italian.html';
document.location.href = 'defaultpage.html';
// End -->



    This is what we have now:

    lang = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")

    real_lang = Left(lang,2)

    'Response.Write real_lang

    Select case real_lang

        case "en"  

            Response.Redirect "/en"

        case "fr"

            Response.Redirect "/fr"

        case "de"

            Response.Redirect "/ge"

        case else

            Response.Redirect "/en"



    End Select




    var langcodes=["fr", "es"];

    // Browser Language Redirect script
    // copyright 3rd January 2006, Stephen Chapman
    // permission to use this Javascript on your web page is granted
    // provided that all of the code in this script (with the sole exception
    // of the langcodes array entries) is used without any alteration

    var langCode = navigator.language || navigator.systemLanguage;var lang = langCode.toLowerCase(); lang = lang.substr(0,2); var dest = window.location.href; for (i=langcodes.length-1;i >= 0; i--){if (lang==langcodes[i]){dest = dest.substr(0,dest.lastIndexOf('.')) + '-' + lang.substr(0,2) + dest.substr(dest.lastIndexOf('.')); window.location.replace ?window.location.replace(dest) :window.location=dest;}}