CFLib.org – Common Function Library Project

ClientLocale()

Last updated April 23, 2002

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

 
Rated 2 time(s). Average Rating: 5.0

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:

view plain print about
Your locale seems to be: <cfoutput>#ClientLocale()#</cfoutput>

Parameters:

No arguments.

Full UDF Source:

view plain print about
<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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
10 day(s) ago

Will Belden Will Belden added
longTime
16 day(s) ago

James Sleeman James Sleeman added
quickSort
26 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
29 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson