Localizing ASP.NET 2 Components


ASP.NET 2 adds many new controls to ASP.NET. In this section, we look at the localization implications of these controls.

Login Controls

Of all the new controls, the Login controls have the greatest textual content. Figure 5.11 shows a selection of Login controls, illustrating their high textual content.

Figure 5.11. Login Controls with High Textual Content


The text used in these controls is not hard-coded. Instead, the text is maintained in properties that have been marked with the Localizable(true) attribute. As such, when Generate Local Resources is run on a page that has one of these controls, the text is copied to a resource and the properties are implicitly bound to those resources. The localization process for these controls, therefore, is the same for any other control (except that the volume of text is higher).

When template controls are added to a form, the controls initially contain text for the language version of Visual Studio. So if you are using the Japanese Visual Studio, the controls will draw from Japanese resources. Visual Studio 2005 does not provide a means by which you can specify a different default language for resources, even if you have the appropriate .NET Framework Language Pack installed.


The LoginName control, however, deserves a special mention. The LoginName control shows the name of the user who is logged in. Often this control is used to display welcome messages such as "Welcome, Rose Tyler, to the Gallifrey Medical Database." The danger here in localization terms is that a developer would build this string by concatenating bits of text. So the text might be built up from "Welcome, "; "Rose Tyler"; and ", to the Gallifrey Medical Database." Not only is this difficult for a translator to translate (because the string has been broken into pieces), but it also will not be acceptable in languages in which the order of the phrases is different than that of the developer's language. For this reason, the LoginName has a property called FormatString. By default, this is "{0}", which acts as a placeholder for the user's name. For this prompt to be correctly localizable, change the FormatString to "Welcome, {0}, to the Gallifrey Medical Database".

SiteMap Control

The SiteMap control is a great new control that is at the heart of ASP.NET's navigation support. The SiteMap itself is simply a description of the nodes in the Web site:

 <?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns= "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >     <siteMapNode url="default.aspx" title="Home"     description="Home page">         <siteMapNode url="Login.aspx" title="Login"         description="Login page" />         <siteMapNode url="CreditHistory.aspx" title="Credit History"         description="Complete Credit History Details" />     </siteMapNode> </siteMap> 


These nodes include the Title and Description of each page, and, clearly, this text must be made localizable. The first step is to create resources from all of the text in the SiteMap. Start by creating a new App_GlobalResources folder, if one does not already exist. Add a new resource filesay, Web.sitemap.resxto this folder and add a resource entry for each of the titles and descriptions. Next enable localization of the SiteMap by adding the enableLocalization attribute with a value of true:

 <siteMap enableLocalization="true" xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > 


Finally, change the siteMapNode Titles and Descriptions to use implicit expressions:

 <siteMapNode url="default.aspx" title="$resources: Web.sitemap, DefaultTitle" description="$resources: Web.sitemap, DefaultDescription">     <siteMapNode url="Login.aspx"     title="$resources: Web.sitemap, LoginTitle"     description="$resources: Web.sitemap, LoginDescription" />     <siteMapNode url="CreditHistory.aspx"     title="$resources: Web.sitemap, CreditHistoryTitle"     description=     "$resources: Web.sitemap, CreditHistoryDescription" /> </siteMapNode> 


The SiteMap is now localizable.




.NET Internationalization(c) The Developer's Guide to Building Global Windows and Web Applications
.NET Internationalization: The Developers Guide to Building Global Windows and Web Applications
ISBN: 0321341384
EAN: 2147483647
Year: 2006
Pages: 213

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net