ASP implements multilingual support

zhaozj2021-02-08  223

ASP implementation multilingual support outline:

Let us imagine that you have designed a successful site using Active Server Pages, and your customers have asked to internationalize this site to provide multiple language versions. What should you do at this time? Please see this article.

text:

First, introduction

Let us imagine that you have designed a successful site using Active Server Pages, and your customers have asked to internationalize this site to provide multiple language versions. The key to this problem is that you must use some way to achieve fast page content conversion. You can see this problem as an appropriate data from the database and dynamically displayed with ASP. In this article we will discuss how to use the Dictionary objects of Active Server Pages and a background database to implement international support.

The specific implementation process is divided into three steps:

◇ Design the database and store text and file path.

◇ Read data from the database to the dictionary object.

◇ 引 Reference text and file paths in the ASP page.

Second, step 1 - Design the database and store text and file path

We need to spend some time in the design of the database. Using this database, we hope to make all the texts and images you want to use, and these texts and pictures cannot be repeated; if you want to change "it" is changed to "OK", you want to change only in one place; The Web maintainer should quickly find the target text when changing the content. Based on the above requirements, let us start designing the database.

First create two tables to place text. One of the tables is Commonstrings, used to store words and phrases that are reused throughout the site. Another table is SpecializedStrings, used to store words and phrases only used in a specific page. Store public and limited pages, respectively, to simplify site maintenance.

Both tables use the StringKey field to tag records, using StringLanguage to illustrate the language used, Joint StringKey and StringLanguage create a primary key. Field StringHolder is used to save words, phrases, or statements. This field must create a unique index to ensure that repetition words, phrases, or statements are not entered.

For the SpecializedStrings table, an additional field asppage is also required to mark the ASP page where the text is located.

For image files, we can create a table with the same steps to store the path to these files. It is only necessary to replace the corresponding StringHolder with the FileName field in the CommONimage table and the SpecializedImage table.

When the data is loaded in the newly created table, StringKey's content should give the site maintor as much prompt as possible to indicate the text that will be displayed on the page. For example, for an online sales site for declaration statements about rejecting commitments, using ORDERDISCLAIMER is a good choice, the site maintainer can now understand the content that will be displayed on the web page very clearly.

Put those common words and phrases in the Commonstrings table. In this way, the maintainer knows if they modify a record in the Commonstrings table, will affect many pages in the site.

For large sites, you can design an easy-to-use interface to enter and modify text in the database. Preparing these information is a lengthy task, the more simple, the less wrong.

Third, step 2 - read data from the database to the dictionary object

Dictionary object is a multi-purpose server-side object, which is equivalent to a two-dimensional array, saving the key, and data associated with the key. The only way to extract data is to get the key value or index. You can configure the scope of the dictionary object to the entire application or dialogue, but don't worry about loss performance. Give the application layer scope means that the object is only instantiated once, and all sessions use the same dictionary object. The following code creates two dictionary object instances, and associates two text tables, respectively. Remember, we hope that the object is only initialized once, so put these code in the Application_onstart event: