Get ColdFusion locale information

December 11, 2010 by Jean

Getting information about a locale is pretty straightforward:

<cfset pc = getPageContext() />
<cfset setLocale("Chinese (China)") />
<cfoutput>
     <ul>
          <li>Current Locale: #getLocale()#</li>
          <li>Language: #pc.getResponse().getLocale().getLanguage().toString()#</li>
          <li>Country: #pc.getResponse().getLocale().getCountry().toString()#</li>
     </ul>
</cfoutput>

Create an instance of a Java locale:

myLocale = createObject("java","java.util.Locale").init("fr","FR"); 

See all available java.util.Locale methods:

<cfdump var="#createObject("java","java.util.Locale").init("fr","FR")#">

<cfdump var="#getPageContext().getResponse().getLocale()#">

In: ColdFusion