Using the Locale Identifier (LCID), Part 2By Scott Mitchell
In Part 1 we discussed how the Web server's regional
settings (editable by the Administrator through the Control Panel's Regional Options icon)
affect the output of VBScript's
Format functions. In this part we'll look at
Session.LCID property to change this default locale on a user-by-user
(or Web page-by-Web page) basis!
Setting the Locale ID on a User-by-User Basis:
While the default locale setting dictates the output of the
what if you want to have the output differ based on the person visiting the page? (Perhaps you
run a site where the user can customize the output or content presented, a site like My Yahoo!
or any of the other customizable portals.)
One option is to use the
LCID property of the Session object (LCID stands for
Locale Identifier). For example, you can specify the Locale for a particular user to be
Estonian by using the following code:
Now, you may be wondering how in the world I knew that Estonian's LCID was 1061. The simplest
way is to consult Microsoft's LCID
table. This handy table contains a listing of all of the various locales and their
associated IDs. By simply changing this locale ID, the output for the VBScript
functions will change for the particular user. Using this property you can automatically
Format functions' output change based on the user's LCID.
One thing to be wary of is currency issues. For example, if I am running an English eCommerce site and have my Web server's regional settings set to English - United States by default, I may have some code that looks like this:
Since, in this hypothetical example, I run an eCommerce site in the US, I mean that the cost
for the shoes are 45 dollars and 56 cents. However, if set a user's
property to, say, 2057 (English - United Kingdom), the shoes would appear to cost 45.56 pounds!
Therefore, if you plan on altering the LCID settings I strongly encourage that you do not
FormatCurrency function or, if you do, that instead of passing a hard-coded value
into the function you pass in the result of some currency exchange rate calculation function:
ConvertFromDollar function would then consult the
property to determine what currency we were converting our dollars to. (You would then need
to use some component like iisCARTex to perform the actual
Setting the Locale ID on a Page-by-Page Basis:
You can also specify the LCID for an entire ASP page instead of on a user-by-user basis. For example, if you had a Web page on your site that, for some reason, you wanted to always use the Hebrew formatting style (LCID 1037) you could do so via the
As with the other ASP directives (
@LCID directive must appear before any ASP or HTML code. For example, to set
an ASP page's LCID to 1037 (Hebrew), we could use the following code:
or, if we wished to specify multiple directives, we could do:
That's all there is to it!
In this article we examined how to set the default locale settings through the Regional Options icon in the Web server's Control Panel. This locale default determines how VBScript's
Format functions produce their output. Any locale setting can be fully customized
for a very unique look and feel for representing numbers, dates and times, and currencies.
ASP also provides a Locale ID on both a user-by-user basis and a page-by-page basis. To
specify a locale ID (LCID) for a particular user, set the
to the appropriate numeric ID. To set the LCID for a particular ASP page, use the
directive. (For a listing of the various LCIDs and their respective values, check out the