Locales

A locale identifies the exact language and cultural settings to use for a user. The locale controls how dates and currencies are formatted, how to display time, and how to display numeric data.

In ColdFusion, a locale is identified by one or more of the elements shown in the following table:
Element
Description
language
This is the basic locale identifier, such as English. This is identified by an ISO 639 two-letter language code.
regional variation
A country code: for example the (US) in English (US). This is identified by an ISO 3166 two-letter country code.
variant
Not commonly used, variants create special locales with additional requirements. A common variant example is the euro variant used by European countries that have adopted the Euro as the currency.

Setting the locale

By default, the ColdFusion locale defaults to the locale of the JVM, which typically defaults to that of the operating system. However, when processing information for a different locale, you must change this default. You can set the locale in the JVM at startup time, or you can use the SetLocale() function within a ColdFusion page.

The SetLocale() function determines the default display format of date, time, number, and currency values. ColdFusion supports 26 locales. For the complete list, see CFML Reference. You use the GetLocale() function to determine the current locale setting of ColdFusion. If you have not made a call to SetLocale(), GetLocale() returns the locale of the JVM.

Note:   In previous versions of ColdFusion, the default locale was always English, not the operating system's locale. For the Japanese version of ColdFusion, the default was Japanese.

The following example code uses the LSCurrencyFormat() function to output the value 100,000 in monetary units for all the ColdFusion-supported locales. You can run this code to see how the locale affects the data returned to a browser.

<p>LSCurrencyFormat returns a currency value using the locale convention. 
<!--- loop through list of locales; show currency values for 100,000 units --->
<cfloop LIST = "#Server.Coldfusion.SupportedLocales#"
index = "locale" delimiters = ",">
<cfset oldlocale = SetLocale(locale)>
  <cfoutput><p><b><I>#locale#</I></b><br>
    Local: #LSCurrencyFormat(100000, "local")#<br>
    International: #LSCurrencyFormat(100000, "international")#<br>
    None: #LSCurrencyFormat(100000, "none")#<br>
    <hr noshade>
  </cfoutput>
</cfloop>

This example uses the ColdFusion variable Server.Coldfusion.SupportedLocales, which contains a list of all supported ColdFusion locales.

Comments