ASP.NET 2 adds many new controls to ASP.NET. In this section, we look at the localization implications of these controls. Login ControlsOf 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 ContentThe 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).
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 ControlThe 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. |