CFLib.org – Common Function Library Project

ClientLocale()

Last updated April 23, 2002

author

Matthew Walker

Version: 1 | Requires: CF5 | 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:

/**
 * 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();
	}		
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson