Localization with ASP.NET C# Help

With ASP.NET applications, localization happens in a similar way to Windows applications. Chapter  7, “ASP.NET Pages,” discusses the functionality of ASP.NET applications; this section discusses the localization issues of ASP.NET applications. ASP.NET 2.0 and Visual Studio 2008 have many new features to support localization. The basic concepts of localization and globalization are the same as discussed before. However, some specific issues are associated with ASP.NET.

As you have already learned, with ASP.NET you have to differentiate between the user interface culture and the culture used for formatting. Both of these cultures can be defined on a web and page level, as well as program.matically. To be independent of the web server’s operating system, the culture and user interface culture can be defined with the <globalization> element in the configuration file web. config:

Language Preference options (see Figure 21-.19). If the page language should be set depending on the language setting of the client, the culture of the thread can be set programmatically to the language setting that is received from the client. ASP.NET 2.0 has an automatic setting that does just that. Setting the culture to the value Auto sets the culture of the thread depending on the client’s settings.

Figure 21-19

Figure 21-19

In dealing with resources, ASP.NET differentiates resources that are used for the complete web site and resources that are needed only within a page. If a resource is used within a page, you can create resources for the page by selecting the Visual Studio 2008 menu Tools ¢ Generate Local Resource in the design view. This way, the subdirectory App_LocalResources is created where a resource file for every page is stored. These resources can be localized similarly to Windows applications. The association between the web controls and the local

resource files happens with a meta: resourcekey attribute as shown here with the ASP.NETLabel control. LabelResour~el is the name of the resource that can be changed in the local resource file:

Appl_GlobalResources. In this directory, you can add resource files, for example, Messages. resx with its resources. Toassociate the web controls with these resources, you can use Expressions in the roperty editor. Clicking the Expressions button opens the Expressions dialog (see Figure 21-20).Here, you can select the expression type Resources, set the name of the ClassKey (which is the name of the .resource file – here, a strongly typed resource file is generated), and the name of the ResourceKey, which is the name of the resource.

In the ASPXfile, you can see the association to the resource with the binding expressions syntax <%$:

Figure 21-20

Figure 21-20

Posted on October 31, 2015 in Localization

Share the Story

Back to Top