Setting the Locale Identifier (LCID)

A locale is a set of user preference information related to the user's language. The locale determines how dates, times, currencies, and numbers are formatted, how items are alphabetically sorted, and how strings are compared. The locale identifier (LCID) is a 32-bit value that uniquely defines a locale. ASP uses the default locale of the Web server unless you specify a different locale for a particular script.

Note

The locale group has to be installed on the Web server before its locale identifier can be specified in a Web page or application. Use the Regional and Language Options control panel application to install locale groups.

To specify the locale for an ASP page, use the AspLCID metabase property, the @LCID directive, the Session.LCID property, or the Response.LCID property.

For example, to set the locale to Japanese, set the AspLCID property for your application to 1041 using one of the following commands:

<%@ LCID = 1041 %> 
<% Session.LCID = 1041 %> 
<% Response.LCID = 1041 %> 

IIS 5.0 and earlier: Response.LCID is not available.

Keep in mind that the code page must be set to display any localized characters that are produced with calls to functions, for example the VBScript FormatCurrency and FormatDateTime. For example, if Response.LCID is set to 1041 for Japanese, Response.CodePage must be set to 932 in order to correctly display the month and day names from a call to FormatDateTime(Date, 1).

When a script is executed, IIS determines how dates, times, currencies, and numbers are formatted using the following hierarchy:

  • On IIS versions 5.1 and later, IIS uses Response.LCID property if it is explicitly set. Else,

  • If Sessions are enabled, and Session.LCID is set explicitly, Session.LCID sets Response.LCID . Else,

  • If @LCID is defined at the top of the page, @LCID sets Response.LCID . Else,

  • If the AspLCID metabase property for the application is set to something other than 0, AspLCID sets Response.LCID . Else,

  • The Web server's default system locale sets Response.LCID.

Setting the locale using one of these methods also sets the locale for the scripting engine, however, setting the locale for the scripting engine with the VBScript function setLocale does not set the locale for ASP.

If you set the locale multiple times in a Web page, you need to set the code page of that Web page to 65001 for UTF-8 and set Response.Charset to "utf-8", so all localized characters show up properly.

The following example is also found in the help topic for Response.LCID:

<% 
Response.Codepage = 65001 
Response.Charset = "utf-8" 

' See what happens when you uncomment the lines below. 
'Response.Codepage = 1252 
'Response.Charset = "windows-1252" 

ShowDateTimeCurrency 1033, "North America" 
ShowDateTimeCurrency 1041, "Japan" 
ShowDateTimeCurrency 1049, "Russia" 
ShowDateTimeCurrency 1031, "Germany" 
ShowDateTimeCurrency 1025, "Saudi Arabia" 
ShowDateTimeCurrency 1081, "India" 
ShowDateTimeCurrency 2052, "China" 
ShowDateTimeCurrency 1042, "Korea" 

Sub ShowDateTimeCurrency(iLCID, sLocale) 
  Response.LCID = iLCID 
  Response.Write "<B>" & sLocale & "</B><BR>" 
  Response.Write FormatDateTime(Date, 1) & "<BR>" 
  Response.Write FormatDateTime(Time, 3) & "<BR>" 
  Response.Write FormatCurrency(1000) & "<BR>" 
  Response.Write FormatNumber(50, 3, 0, 0, -1) & " & " & FormatNumber(.02, 3, 0, 0, -1) & "<BR><BR>" 
End Sub 
%>