Working with International Sites

One of the advantages of distributing information over the Internet or over an intranet is that you can create international Web sites that users can access from different countries. Users can request pages that have been localized into their own language, which they read in localized browser versions. When you create a Web site that contains pages in different languages, you may need to convert strings that are passed between the browser and the Web server or between an ASP script and an ActiveX component. For example, if a Japanese browser sends form or query string values in the HTTP request, the strings must be converted from the browser's Japanese character set into the character set that ASP uses to process scripts.

If all pages on the Web site are written in the default character set used by the Web server, ASP does the conversion automatically. If you author pages in different character sets, however, you need to use ASP commands that specify how the strings should be converted. For example, if your site contains some pages in one of the Japanese character sets and others in one of the Chinese character sets, you need to specify which character set ASP should use while processing strings for a particular page.

ASP also provides commands that support the cultural conventions for different locales, such as the format used for currency, time, and date. As with the string conversion commands, you only need to use the locale commands if your scripts do not use the default locale for the Web server.

Setting the Code Page for String Conversions

A code page is an internal table that the operating system uses to map symbols (letters, numerals, and punctuation characters) to a character number. Different code pages provide support for the character sets used in different countries. Code pages are referred to by number; for example, code page 932 represents the Japanese character set, and code page 950 represents one of the Chinese character sets.

Active Server Pages and the ActiveX script engines internally use Unicode, a 16-bit fixed-width character encoding standard. If you author all of your pages in the default code page of the Web server, ASP automatically converts strings. If your script was not created in the Web server's default code page, however, you need to specify the code page so that strings are correctly converted as they are passed between ASP and the script engines. In addition, you can specify the code page for strings that are passed between the browser and your script or between ActiveX components and your script.

To specify the code page for an ASP page, use the CODEPAGE directive. For example, to set the code page to Japanese, use the following directive:

<%@ CODEPAGE= 932 %>

As ASP processes the content and script on this page, it uses the code page you have specified to determine how to convert characters from your script's character set into Unicode. For example, the value that refers to the letter "a" in ANSI will be converted into the different value that refers to the letter "a" in Unicode.

Active Server Pages assumes that strings passed between the Web server and the browser, or between your script and ActiveX components, are in the same code page you have set for your script. If you need to specify a different code page, you can set the Session.CodePage property to override the CODEPAGE setting. For example, you may have authored your script in JIS but need to respond to a client that is using UTF-8 (two different character encodings for the standard Japanese character set).

Session.CodePage defaults to the value of the CODEPAGE directive; setting it overrides the current CODEPAGE setting. For example, to change the code page to Chinese, use the following command:

<% Session.CodePage = 950 %>

If you are temporarily changing the code page for a portion of your script, be sure to set Session.CodePage back to its original value. The following script shows how to temporarily change the code page:

<!-- Welcome to my home page in Japanese, code page 932 --!>
<%@ CodePage = 932 %>
...
<% Session("OriginalCodePage") = Session.CodePage %>
<!-- Look up name in Chinese, code page 950 --!>
<% Session.CodePage = 950 %>
<% Sender = ReadMailHeader("Sender") %>
<% Found = FindFriend("Sender") %>
<!-- Restore the original code page --!>
<% Session.CodePage =  Session("OriginalCodePage") %>
<% If Found == TRUE 
	ReplyWithPersonalizedForm()
     else
	ReplyWithBusinessForm()
%>

Setting the Locale Identifier

A locale is a set of user preference information related to the user's language. The locale determines how dates and times 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.

To set the locale identifier for an ASP page, use the LCID directive. For example, to set the locale to Japanese, use the following locale ID:

<%@ LCID =  1041 %>

The LCID directive tells ASP the locale in which the script was authored. If you need to change the locale for input to or output from the script, use the Session.LCID property. For example, to set the locale to Standard French, use the following command:

<% Session.LCID = 1036 %>

The Session.LCID property defaults to the LCID directive setting. Setting the value of Session.LCID in a script overrides the default setting.