Since the Internet has emerged 10 years ago, corporate groups have continued to open up international markets. Businesses not only have global network rendering through their own Web site, but more and more companies are also publishing and / perhaps enterprise-level web applications in order to eventually serve customers around the world. Since most customers prefer to conduct business in their language and environments, it is necessary to prepare localized web sites and applications. There is no doubt that no matter which deployment model (intelligent client, web site, web service), in particular, the architecture and design, the localization task needs to pay time and energy. Effective development tools can affect the quality of the architecture, but weird is that it is still insufficient for developing tools for the localization of web applications. Results Many companies have to help more traditionally, more troublesome localization, and spend a lot of time and money.
Microsoft ASP.NET 2.0 version promises to better transform the web developers to achieve localization. By using more tools, new runtime features, new runtime, and a new-specific programming API, new runtime, and a newly-specific programming API, and developers can be quickly separated from the ASP.NET page. Reduce the code to access the localized content, expand the environment that meets the additional demand, and integrates a consistent programming model. This article will lead you to an ASP.NET development that is newly improved to prepare localized applications.
Localization using .NET 1.x
.NET Framework 1.x introduces a new localization architecture that provides non-inserted progressive deployment for language support, and the method is to drag and drop it into the new accessory set (or only resource assemblies). This type of spoke deployment example allows developers to manage localized content that is accurately selected by the ResourceManager class by the public language runtime. One advantage of ResourceManager is that it interacts with a packaged resource callback mechanism. The most appropriate language is found according to the runtime language settings of the application, so loading each ResourceSet to retrieve the process of localized content without the need to write code for management.
Windows or web applications can use resources to localize Windows forms, but Visual Studio 2003 makes the Windows developer's localized Windows form easier. When a Localizable property of a form is set to TRUE, resources for localized FORM and Control properties will be automatically generated. The attribute value is pressed into the default resource for later translation, through these resources, the generated code uses the resourceManager class instance fill control when running. ResourceManager first considers the Currentuiculture settings that are performing threads, and try to find the resource of the matching language in the resourceset, and finally help the resource callback process.
Note Please read the information about the resource callback process here.
The .NET Framework also contains many class-related classes that consider Currentuicultuiculture when generating output results such as formatting dates, time, and currency values, thereby further reducing the workload required for developers.
Note Please read more information about the language related to the language from the MSDN reference resource.
Although the deployment model of the accessory assembly can be applied to the ASP.NET application, the tools that are missing to developers can be integrated into the programming example of the Web Form. Currently, resource entities are generated for the web page, access these resources at runtime, and the correct language for each request is required to complete. So the web application localization does not have much consideration to use resources as an integration section. Localization Web Contents have caused a website that repeated the entire specific language, whereby localization of static content and writing custom code for any shared code to manage localized data sources. ASP.NET 2.0 greatly improves the method. Note MSDN article discussed the structured method for ASP.NET 1.1 localization.
Back to top
ASP.NET 2.0 New Localization Function
ASP.NET 2.0 is built on the .NET 1.x localization function, which has implemented the functions available to workflow and web developers. The following summarizes the design objectives to facilitate the next generation of localized support:
• Provide a tool for web applications that support resource generation. • Provide new declarative and runtime programming constructs for resource access. • Simplify the process of applying the correct language and automatically instantiate ResourceManager for page requests. • Support for XCOPY deployment and compilation steps of small commercial sites. • Support for enterprise-level development versions with scalability of all resource resources. • Make sure that ASP.NET controls and other applicable runtime components and adapters integrate new localization functions.
Visual Studio 2005 and ASP.NET 2.0 integrated new features ensure that the web application is localized, it provides tools to extract localized content from the web page, providing integrated runtime support for resource supporting the stateless request model, through Advanced declarative constructs Bind resources to page output, providing a new way to automatically select language for round-trip processes. The following features are specifically used to support these goals:
Strongly Typed Resources - The core status of the .NET Framework 2.0 is strong type resource support, which provides the developer to provide intelligent awareness, simplifying the code required to access the resource at runtime.
Managed Resource Editor - Visual Studio .NET 2.0 includes a new resource editor to better create and manage resource instances, such as strings, images, external files, and other complex types.
Resource GenerationFor Web Forms - Windows Form developers have benefited from automated internationalization. Now, Visual Studio 2005 will support fast internationalization, automatically generate web forms, user controls, and homepage resources.
The Improved Runtime Support - ResourceManager instance is managed by runtime, and server code can easily access it through more accessible programming interfaces.
Localization Expressions - Advanced declarative expressions for web pages map resource entities to control properties, HTML properties, or static contents. These expressions can also be extended, providing other methods to control the process of adding localization content to the HTML output.
Automatic Culture Selection - The language selection of each web request can be automatically connected to the browser preference.
Resource Provider Model - A new resource provider model allows developers to publish resources for optional data sources (for example, flat files, database tables), while accessing the programming models of these resources remain consistent.
These flexible functions are sufficient to provide a bits support for small companies that need reliable and effective solutions, and still meet the complex needs of large organizations to apply a variety of deployment architecture in additional scalability. The improved new model uses the resources of the web application, combines the Windows Form Programming model, and considers the development cycle and the runtime requirements of the Web. The following sections describe these new features implemented in the beta 1 version, and also commented on the improvements you expect in the Beta 2 versions. Back to top
Generate local resources
The .NET resource implements selectively replaces the content for a particular language and language area, so the same code base can support multiple languages. However, generating resources for web pages requires a lot of artificial labor, so it is difficult to mobilize the enthusiasm of developers using this method for web applications. ASP.NET 2.0 provides a simple way to generate resources for web pages while supporting a variety of complex content agents, including HTML elements, and properties, static content, and server controls.
Generate resources for a specific web form, you need to select Generate Local Resource from the "Tools" menu of Visual Studio 2005, and then create local resources for any page that is opened in the Design View (including Web Forms, User Controls, and Main Perspections). This step automatically generates a default .NET XML resource for a set of pages, placing it in a dedicated subdirectory established for local resource (change this directory name in Beta 2).
Figure 1. Web form, user control, and home page can be internationally internationally within Visual Studio .NET 2.0. This particular view is displayed as a default resource generated by some pages.
Local resource stores in .resx files, file naming rules correspond to the page served by local resources (see Figure 1). For example, after generating resources for the homepage named Site.Master, the new .resx file appears in / localResources. For web forms named Default.aspx, the generated resource is stored in a file called Default.aspx.resx.
Visual Studio Designer Checks Page and Its Controls (ASP.NET Server Control, Custom Control, and HTML Controls Set to Runat = "Server" - Find the properties tagged as localizableam - and populate these resources:
[Localizable]
Public Virtual String Text
{
Get {...}
Set {...}
}
The localized property of each control automatically presses the resource, uniquely identifies each property with the keyword. The keyword contains a prefix that identifies the page control name and attribute name. Each attribute value is set to the default value of the control unless specified in the control declaration. The following LinkButton declares a value specified for PostbackURL and Text properties:
Runat = "Server"> Change SELECTED CULTURE ask: LINKBUTTON> Figure 2 shows the resource generated for the LinkButton after generating local resources for the host page (see CultureInfo.ascx in the sample project). Resources are stored in the resource file (see CultureInfo.ascx.resx), which is default unmatched attributes such as PostBackURL. Figure 2. The hostage of the HTML control of the ASP.NET server control, custom server control, and server-side HTML controls generate local resources. When generating resources, the control declaration is also modified to declare that the attribute is associated with the resource entity. Some new declarative expressions are also identified for the page parser, which triggers code generation, using resource values to fill control properties at runtime. The declarative localized expression is a new construction of ASP.NET 2.0, similar to data binding statements, is specifically designed for accessing resources. These expressions have two forms: implicit and display. Implicit expression is automatically inserted when generated local resource generation and supports multiple resource entities to a set of control properties in a single declaration statement. Explicit expression is a declaration that developers added for further control of page localization. The following hiped expressions identified by Meta: ResourceKey are generated for the LinkButton declaration, now, it sets the resource key prefix for this control: Runat = "Server" Meta: ResourceKey = "LinkButtonResource1"> Change Selected Culture ask: LINKB /TON> After the resource entity of the control property uses this prefix, the runtime will automatically map to the correct control attribute. Each attribute value in the control declaration remains originally unable, including those values that are pressed into the resource. These default values will appear in the Design View, provide contexts for controls within the page. When parsing the page, the code generated by the localized expression applies the resource to the control properties. Developers do not need to write the code to instantiate the ResourceManager to access these local resources at runtime. The runtime resource value is prioritized, and no resource is replaced by the default value. This is very useful for web developers because they can view page content before the site deployment is completed. In Properties WINDOW, the localized content is labeled by a special icon, indicating that their value is extracted from the resource. Figure 3 shows an ASP.NET ImageButton control, some of which bind to the shared resource (with blue identity), and other bind to local resources (with red identity). The contents of using expressions binding properties will be discussed in depth in the back section. Figure 3. In the Properties WINDOW view, it is easy to locate the localization content identified by the special icon. So far, the focus of discussion is to generate local resources. By default, it is intended to generate implicit localized expressions and resources for localized control properties, and attributes binding attributes to shared application resources. In addition, it may also automatically generate local resources for non-localized control properties, other HTML elements, and static content. Apply explicit localized expressions to these pages and control elements. In other words, developers can declare to identify content that require localization so that the resource generation of the page contains these content or selectively extract from alternatives. Back to top Shared application resources Automatically generate local resources for each page will cause resurgence and excess translation work. Fortunately, ASP.NET 2.0 has a reuse model established by the home page and user control, which supports headlines, menus, bars, and other parts of HTML in Web forms. Each home page, user controls, and web forms have their own local resource collection, which reduces resource repetition. Moreover, the resource entity, such as terms, error messages, and function drivers (for example, direction attributes) are very useful when merging and sharing between all pages. The local resource of each page is automatically generated by the designer, while the shared application resources need to be created manually. This means adding a new application resource to the solution, placing it in a dedicated directory specified by the shared resource (this directory will be changed) in Beta 2). This is consistent with the method of generating shared resources in the 1.x application, however, the new resource editor simplifies creation and editing resource entities, and shared resources have been intelligent through intelligent perceivement support. Shared resources are also involved in the resolution of the new page and the runtime model of ASP.NET 2.0. They can be bound to the page by explicit localization expressions, at this time, the ResourceManager automatically instantiates and caches, and developers do not have to manage the life cycle of the running access resource. Figure 2 and Figure 4. Display a new Managed Resource Editor for Visual Studio 2005. Figure 2 is a resource string editor that is similar to the resource editor in Visual Studio. Figure 4 illustrates a list of predefined resource types supported by the editor, including strings, icons, other image file types, audio file types, and other files with XML. In addition to these predefined types supported by the resource editor, it is also possible to program other complex types into resources. At this time, the basic resource file is based on XML. Figure 4. New Managed Resource Editor integration supports a variety of predefined data types, providing replacement views, showing a thumbnail of Image resource types. Document-based resources (eg, images, sounds, and XML files) are inserted via the editor, defined by default as a RESXFILEREF entity. For example, the following code is an external image and an XML file, respectively, a resource entity: System.drawing, Version = 2.0.3600.0, Culture = Neutral, PublicKeyToken = B03F5F7F11D50A3A value> data>
Runat = "Server" Meta: ResourceKey = "LinkButtonResource1"> Change Culture Settings ask: LINKBUTTON> This expression sets the expected prefix for all resource entities related to the control properties - thus implicit expression. Automatic resource generation only considers localization properties, but actually any resource entity, you can bind to this property in the compiled page code as long as you use the prefix with a legitimate property name. In the example above, LinkButtonResource1 is a resource keyword prefix, and the resources displayed in Figure 2 are applied to all attributes of the same control instance (i.e., LinkButtonResource1.text) use this prefix. This declarative statement (META: ResourceKey) notifies the ASP.NET page parser generating code for retrieval attribute values from the default local resource. Results The code is ultimately accessing the resource using the runtime method with the help of getPageResourceObject (in this method name in Beta 2). In the sample code provided, the compiled CultureInfo.ascx page uses the following code to create and instantiate LinkButton and LNKSelectCulture: LinkButtonButton1 = new linkbutton (); THIS.LNKSELECTCULTURE = Button1; Button1.id = "lnkselectculture"; Button1.postbackURL = "Selectculture.aspx"; button1.accesskey = (String) Base.getPageResourceObject ("LinkButtonResource1.accessKey)); Button1.softKeyLabel = (String) Base.getPageResourceObject ("LinkButtonResource1.softKeyLabel")); Button1.text = (String) Base.getPageResourceObject ("LinkButtonResource1.text"))); Button1.tooltip = (String) Base.getPageResourceObject ("LinkButtonResource1.tooltip"); Button1.visible = ((bool) Base.getPageResourceObject ("LinkButtonResource1.visible", TypeOf (Control), "Visible"); Implicit localized expressions are applied to all server control declarations when generating page resources. You can use the following alternative syntax to cancel this behavior, indicating that the control should not be localized: Runat = "Server" Meta: localize = "false"> Change Culture Settings asp: linkbutton> Individual control properties that are not important to localization strategies can manually remove them from local resources using the Managed Resource Editor shown in Figure 2. This reduces the number of code generated by the page parser to apply the local resource entity to the control attribute, as the code only reflects those entities existing in the default local resource of the page. This also means that additional keywords added to localized resources will not be applied at runtime because this is not generated. Such localized expressions use the new Expression Builder that is released with .NET Framework 2.0. Implicit localized expressions generate code from a single declarative statement to populate all the localized server control properties to save the developers. At the same time, it also deletes a manual step required to currently 1.x web applications, ie, a custom data binding statement or custom code is usually required to extract from a localized resource or data source. The following will preview how to automatically generate additional resources for static text and specific control properties (including those who do not have a localizableAttribute tag). Back to top Explicit localized expression Although it is easy to automatically generate resources for localized control attributes, developers also need a solution that supports localized specific attribute values and other content blocks. Explicit localization expressions are assigned a specific resource entity to the server control properties and other HTML elements. For example, the following imageButton control declaration uses an explicit expression to set the AlternateText property: ImageURL = "~ / images / idositelogo.jpg" AlternateText = '<% $ resources: missionStatement%>' PostbackURL = "http://www.idesign.net" /> Explicit localized expressions use the following syntax: <% $ resources: [ApplicationKey], ResourceKey%> The above example omits ApplicationKey because the MissionsTatement value is extracted from local resource. The resourceKey value identifies the extracted resource entity, and the default value represents the designer default value. The designer default value exists only when designing, providing a developer or web designer editing page layout. Explicit expression can also be generated by the Expressions dialog box in the "Properties" window shown in Figure 6. This dialog supports creation of explicit expression values to bind control properties to local resources or shared resources. Figure 6. Using the Expressions dialog box, developers can visually map resources to properties and generate explicit localized expressions. With this dialog, developers can create explicit expressions using the "Properties" window, just like setting other control properties. If ClassName is omitted in Expression Properties (see Figure 6), the drop-down list will display the available local resource keywords (assuming a resource has been created). Otherwise, the explicit expression corresponding to the local resource will generate a local resource entity that matches the keywordKey. This else reduces the workload required for developers to create resource entities and generating fill properties at runtime. If you access a shared resource, classname should identify an legitimate resource file name in the global resource directory. Unlike local resources, the explicit expressions corresponding to shared resources do not automatically generate these resources. Implicit and explicit localized expressions can be used in order to extract from shared resource, while other properties are extracted from local resource. The following code example shows that the ImageButton control declares gets the AlternateText property from a shared resource (Glossary.resx), all other properties use implicit expression syntax from local resource extraction: ImageURL = "~ / images / idositelogo.jpg" AlternateText = '<% $ resources: glossary, missionsatate%>' Postbackurl = "http://www.idesign.net" Meta: ResourceKey = "ImageButtonResource1" /> td> After using explicit localized expressions, where the details are controlled, which attributes will be possible to be implemented. For control declarations including explicit and implicit expressions, page resources are generated in the following: • Explicit expression binding properties If a shared resource is specified, it will be omitted in local resource generation. • The properties of the explicit expression binding of the local resource generates a resourceKey entry point for a default value. • The remaining unbinded expressive properties of explicit expressions, generate a resourceKey.PropertyName entry point with the default attribute value of the control declaration or control. As previously mentioned, the page is parsed, the code in the declaration is automatically generated in order to extract the attribute value from the shared or local resource. In the sample code above, the resulting code creates an ImageButton control, sets the AlternateText property from the Glossary shared resource, and the remaining localized properties are set by local resource settings: imageButtonButton1 = new imageButton (); // Other Initialization Code Button1.id = "btnidesign"; Button1.accessKey = (String) Base.getPageResourceObject ("ImageButtonResource1.accessKey); Button1.alternateText = (string) Base.GetAppResourceObject ("Glossary", "MissionStatement"); Button1.imageURL = (string) Base.getPageResourceObject ("ImageButtonResource1.imageurl); Button1.tooltip = (string) Base.getPageResourceObject ("ImageButtonResource1.Tooltip"); Button1.visible = (bool) Base.getPageResourceObject ("ImageButtonResource1.visible", TypeOf (Control), "Visible"); Back to top Localized HTML element and static text Use implicit and explicit localization expressions, making it easy to generate resources for server control properties. However, preparing to localize a page, you must also consider other content such as HTML pages, direction properties, and static content. Localization expressions can also be applied to @PAGE instructions and other parts of HTML, first declare the other localization part of the generated page resource. HTML control: The HTML control is running on the server (runat = "Server") to reflect the advantages of implicit or explicit expressions. Once marked as a server-side control, a local resource that is automatically generated to the localized property applied to the control. HTML Server Controls are like ASP.NET, custom server controls, can also bind to implicit or explicit expressions, which can be generated using the previously mentioned Expressions dialog. The HTML element of the header head can also be declare to resource, which is useful for page headings and style sheets. The HTML page title element is very special, because it is also a PAGE property that can be set by @PAGE instructions. By default, hidden expressions are assigned to each page when generated by the local resource: <% @ Page language = "c #" codefile = "default.aspx.cs" inherits = "_ default" Meta: ResourceKey This expression can also be modified to an explicit expression for extracting values from a shared resource (not local resource): These expressions cannot cover the title> hEAD> Directional attribute Improved direction setting support is added by the new Direction property, which is supported by controls such as In order to control the direction of the browser scroll bar and set the overall direction of the site, the following explicit expression is extracted from the shared resource by the designer default value "LTR": >>> ... asp: panel> For more information on the Visual Studio .NET direction, please visit this site. Static text Localization expressions are used to set control properties and other HTML elements; however, many web pages to perform localized Web have already included a large amount of static content blocks with ASP.NET controls. The new ASP.NET Localize control is used to mark the static content as a localized so that the resource generates this part of the static content. If the Control is the message of Meta: ResourceKey, the specified keyword (equally adapted to other controls): Meta: ResourceKey = "Welcome"> Welcome! asp: localize> The above example generates a new local resource entry point for the Text property of the Localize control, and the resource prefix is "Welcome.Text). To explicitly populate static content from a shared resource, you can specify a Text property through an explicit localized expression: ASP.NET 2.0 introduces a new feature that automatically selects runtime language based on the favorite of the WEB browser. The @PAGE instruction is used to identify whether the specific page should be performed according to the browser's preference, it also supports the settings of the language and UI language: <% @ Page uicle = "auto" culture = "auto"> application web.config file can also apply this setting to the entire application: If the HTTP header is not available, the AUTO's colon allows you to specify a default language. Because a specific language must be set, the above example must be EN-US as a language displayed. The final result is the actuT_lang header that automatically detects the browser when running, and the thread is set to the first language in the user language preferred list in the early stage of the page cycle. If a configuration file is stored for the application, or the user can select a specific language through the site, the developer must write code to override the AUTO settings processed at runtime. The sample code illustrates a use skill of this situation. Back to top summary In order to more quickly adapt to the requirements of product release throughout the world, it is imperative to define a globalization strategy in the early days of the development cycle. Using ASP.NET .0 These new localization features, developers can make more easily implement the strategy of localized applications, while reducing the system overhead of the development cycle. The page resource automatically generated and the new Managed Resource Editor makes creating a web application resource more natural. Using a declarative localized expression, you may ensure that all necessary page elements are localized and help automatically generate appropriate page resources. A new runtime model means that developers can choose no longer compile the subscriber set, no longer instantiate the resource manager, and do not set the request thread according to the language. It will eventually be conducive to publishing a strong web application with a single code set, thereby reducing the cost and payment of the solution applied to the global market.