ASP Lecture Series (Twenty-Two) Using International Sites
Author:Eve Cole
Update Time:2009-05-30 19:58:30
One advantage of publishing messages on the Internet or intranet is that you can create an international Web site that users can access from different countries (regions). Users can apply for web pages that have been localized into the local language and read them using the localized version of the browser. When building a Web site that contains web pages in multiple languages, you need to convert strings passed between the browser and the Web server or between the ASP script and ActiveX components. For example, if a Japanese browser sends a form or query string value in an HTTP request, this string must be converted from the browser's Japanese character set to the character set that ASP uses to process the script.
If all pages on the Web site are written in the default character set used by the Web server, ASP will automatically perform the conversion. However, if the web page is written in another character set, you must use ASP commands to specify how to convert the string. For example, if your site has both Japanese character set pages and Chinese character set pages, you must specify the character set that ASP uses when processing a particular page.
ASP also provides commands that support cultural conventions in different regions, such as currency, time, and date formats. As with the string conversion command, use the locale command if your script does not use the Web server's default locale.
Setting the String Conversion Code Page A code page is an internal table that the operating system uses to map symbols (letters, numbers, and punctuation marks) into character numbers. Different code pages support character sets used by different countries (regions). Code pages are referenced by numbers; for example, code page 932 represents the Japanese character set, and code page 950 represents the Traditional Chinese character set.
Active Server Pages and the ActiveX scripting engine internally use Unicode, a 16-bit fixed-length character encoding standard. If you write all pages that use the Web server's default code page, ASP will automatically convert the strings. If your script does not use the Web server's default code page, you should indicate the code page used so that strings are converted correctly when passed between ASP and the script engine. Additionally, you can specify the code page for strings passed between the browser and script, or between ActiveX components and script.
To specify a code page for an ASP page, use the CODEPAGE directive. For example, to set the Japanese code page, use the following command:
<%@ CODEPAGE= 932 %>
When ASP processes the content and scripts of this page, it uses the code page you specify to determine how to convert the characters in the script from your script's character set to Unicode. For example, a value representing the letter "a" in ANSI will be converted to a different value representing the letter "a" in Unicode.
Active Server Pages assumes that the code page of strings passed between the server and the browser or between a script and an ActiveX component is the same as the code page that you set for the script. To specify a different code page, you can override the CODEPAGE setting by setting the Session.CodePage property. For example, you write scripts using JIS, but respond to clients that use UTF-8 (JIS and UTF-8 are two different character encodings of the standard Japanese character set).
Session.CodePage is set by default to the value of the CODEPAGE directive; setting this property will override the current CODEPAGE setting. For example, to change the code page to Traditional Chinese, use the following command:
<% Session.CodePage = 950 %>
If you only temporarily change the code page of part of the script, be sure to set Session.CodePage to the original value afterward. 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 site identification site is a set of user preference information related to the user's language. Determine on the spot how to format dates and times, items; how to sort alphabetically and how to compare strings. The Site Identification (LCID) is a 32-bit value that uniquely defines a site. If you do not specify a different locale for the script, ASP uses the Web server's default locale.
To set the context identification for an ASP page, use the LCID directive. For example, to set up a Japanese site, use the following site ID:
<%@LCID = 1041 %>
The LCID directive tells ASP the locale in which to write the script. If you want to change the input or output context of a script, use the Session.LCID property. For example, to set the locale to standard French, use the following command:
<% Session.LCID = 1036 %>
The default setting for Session.LCID is the setting of the LCID directive. Setting the value of Session.LCID in a script will override the default setting.