CFLib.org – Common Function Library Project

ClientLocale()

Last updated April 23, 2002
Download UDF

author

Matthew Walker                                    Matthew Walker

Version: 1 | Requires: ColdFusion 5 | Library: UtilityLib

Description:
This function uses the CGI variable HTTP_ACCEPT_LANGUAGE to attempt to choose an appropriate locale for the visitor. You could then use this locale when displaying dates, numbers, etc. or handling data entered by the visitor.

Return Values:
Returns a string.

Example:

Your locale seems to be: <cfoutput>#ClientLocale()#</cfoutput>

Parameters:

No arguments.

Full UDF Source:

<cfscript>
/**
* Attempts to deduce the visitor's locale.
*
* @return Returns a string.
* @author Matthew Walker (matthew@cabbagetree.co.nz)
* @version 1, April 23, 2002
*/

function ClientLocale() {
    var FirstLocale = SpanExcluding(CGI.HTTP_ACCEPT_LANGUAGE, ",;");
    var LanguageCode = ListFirst(FirstLocale, "-");
    var CountryCode = "";
    if ( ListLen(FirstLocale, "-") EQ 2 )
        CountryCode = ListGetAt(FirstLocale, 2, "-");
    switch(LanguageCode){
            case "nl":
            switch(CountryCode){
                    case "be":
                    return "Dutch (Belgian)";
                default:
                    return "Dutch (Standard)";
            }        
        case "en":
            switch(CountryCode){
                    case "au":
                    return "English (Australian)";
                case "ca":
                    return "English (Canadian)";
                case "nz":
                    return "English (New Zealand)";
                case "gb":
                    return "English (UK)";
                case "us":
                    return "English (US)";
                default:
                    return "English (UK)";
            }        
        case "fr":
            switch(CountryCode){
                case "be":
                    return "French (Belgian)";
                case "ca":
                    return "French (Canadian)";
                case "ch":
                    return "French (Swiss)";
                default:
                    return "French (Standard)";
            }
        case "de":
            switch(CountryCode){
                case "at":
                    return "German (Austrian)";
                case "ch":
                    return "German (Swiss)";
                default:
                    return "German (Standard)";
            }        
        case "it":
            switch(CountryCode){
                case "ch":
                    return "Italian (Swiss)";
                default:
                    return "Italian (Standard)";
            }    
        case "nb":
            return "Norwegian (Bokmal)";    
        case "nn":
            return "Norwegian (Nynorsk)";
        case "pt":
            switch(CountryCode){
                case "br":
                    return "Portuguese (Brazilian)";
                default:
                    return "Portuguese (Standard)";
            }    
        case "es":
            switch(CountryCode){
                case "mx":
                    return "Spanish (Mexican)";
                default:
                    return "Spanish (Modern)";
            }        
     default:
            return GetLocale();
    }        
}
</cfscript>

Search CFLib.org


Latest Additions

Jose Diaz-Salcedo Jose Diaz-Salcedo added
cfRssFeed
2 day(s) ago

Raymond Compton Raymond Compton added
structBlend
23 day(s) ago

Duncan Duncan added
IsZIPUK
23 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
29 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson