Skip to main content
Inspiring
November 15, 2008
Question

Get Locale country and language codes

  • November 15, 2008
  • 12 replies
  • 8403 views
I have checked the documentation, but nothing is jumping out at me. Is there a function that returns the locale country and language codes? GetLocale() returns the "locale name as it is represented in ColdFusion":

ie:
English (US)
Spanish (Standard)
...

What I am looking for is the ISO codes

en US
es ES
...

I can get the information using getPageContext(), but just wondered if I was overlooking a built-in CF function.
This topic has been closed for replies.

12 replies

Inspiring
November 18, 2008
> yup. default is en_US. your snippet shows just "en" for that default
> (once the cf locale is changed it shows es_ES as expected).

Weird. But thanks for the "heads up". I will use the java default instead.
Inspiring
November 15, 2008
Hi,
The attached function from my library returns a query object with local information. You can use the query to fill a country listbox, but you can also SQL SELECT it to find the info you need.

cheers,
fober



<cffunction name="locales_query" output="Yes">
<cfargument name="query" type="variableName" default="rs_items">

<cfset rs_locales = QueryNew("DisplayName, Locale")>

<cfset z= 1>
<cfloop index="x" list="#Server.ColdFusion.SupportedLocales#">
<cfset temp= QueryAddRow(rs_locales)>
<cfset temp= QuerySetCell(rs_locales, "DisplayName", "#GetLocaleDisplayName(x)#", z)>
<cfset temp= QuerySetCell(rs_locales, "Locale", "#x#", z)>
<cfset z=z+1>
</cfloop>

<cfset "#query#"= rs_locales>
</cffunction>
Inspiring
November 15, 2008
Thanks, but it is not quite what I am looking for.

The problem with the functions I have seen is that they return locale name as it is represented in ColdFusion (ie English (US) ). But what I am looking for the ISO language and country codes.
http://java.sun.com/javase/6/docs/api/java/util/Locale.html#getCountry()