Home   Preview the Book   Chapter 15, TOC   Part 8

  Previous: Implementing a Web Design
  Next: Modifying the Structure of a Web Page in Code

Localizing a Web Page Design

We covered the localization of Web pages in Chapter 13. In a nutshell, you create separate resource files for each language that your Web site will support. Your code accesses the localized strings through a System.Resources.ResourceManager instance declared like this:

Protected rm As ResourceManager

In the Page_Load procedure, you instantiate the ResourceManager class with a statement such as the following:

rm = New ResourceManager("Chapter_15.strings",
GetType(index).Assembly)

The ASPX file inherits the code behind that’s specified in its Page directive and uses the protected ResourceManager instance to supply the correct values for all localized strings. After you paste the content area from the design into the corresponding ASPX file, you simply go through the HTML looking for strings such as

<span class="lblform">Password:</span>

Replace each string with the corresponding localization element, like this:

<span class="lblform"><%=rm.GetString("Password")%></span>

As we explained in Chapter 13, localizing strings in this manner requires the addition of an RESX file to your application for each language that your Web application will support. However, there can be benefits to localization even if you don’t plan your Web application to be multilingual. Should the phrasing or terms used in a Web site change, whether because of marketing or other considerations, you can make all of the corrections in the RESX file without having to hunt them all down in the HTML for all the Web pages in the application. Figure 15-6 and 15-7 show screenshots of the VB Snippets homepage, index.aspx, in English and German.

Figure 15-6. The localized index.aspx page obtains its strings via a ResourceManager instance rather than hard-coded HTML.
Chapter 15, Figure 06.

Figure 15-7. When a visitor’s browser specifies German as the preferred language, the index.aspx page responds accordingly.
Chapter 15, Figure 07.

One thing you won’t be expected to do as a programmer is to provide the translations yourself. For the VB Snippets case study, we obtained the translations from the Internet to illustrate the mechanics of localization, but for a real application we would employ a professional translator.

Note that the controls on the page have also been localized, including the graphical Log In button. As you will see shortly, the localization of controls works just like the localization of Web pages.

  Previous: Implementing a Web Design
  Next: Modifying the Structure of a Web Page in Code

Home   Preview the Book   Chapter 15, TOC   Part 8

Copyright © 1996 - 2017 SoftMedia Artisans, Inc. All Rights Reserved.