|
Microsoft ASP.NET LocalizationThis page describes how to get ASP.NET applications to display text and images in multiple languages. |
|
Unlike PHP, Microsoft's ASP.NET was designed to natively support Unicode which can display the character sets of all languages in the world.
The trouble with internationalizing ASP.NET applications is that several approaches are available.
Microsoft initial 1.1 release of .NET required coding ResourceManager.
.NET 2.0 and Visual Studio 2005 introduced Custom Tool ResXFileCodeGenerator which, when a project is compiled (rebuilt), generates code in the .Designer.cs to access resources for each culture in satellite assembly (.dll file) which contain no code.
This generates a .NET managed ResourceManager class that exposes every resource in the *.resx file as a strongly typed static property of the Microsoft Core Library (mscorlib.dll) ResourceManager class which looks up culture-specific resources.
It has a return type System.Resources.ResourceManager
To retrieve culture-specific resources, this code is inserted:
Build Action has value of Embedded Resource ???
To support versioning the main assembly without redeploying satellites,
the SatelliteContractVersionAttribute is specified.
To avoid looking up a satellite assembly that might never exist,
the NeutralResourcesLanguageAttribute is specified.
The Windows Forms Resource Editor (Winres.exe) tool within the Windows Software Development Kit (SDK) supports localization of Windows Forms dialogs.
MSDN article notes that it follows links in .resx files and checks timestamps in them as well. <LogicalName>someQualifier.someResource.resources</LogicalName>
Microsoft MSDN on Assembly Linker is built into the VS 2008 compiler.
This is a problem of performance because each satellite assembly file takes some time to load, making an application internationalized in the default way take significantly longer to start-up.
The problem is that the class was created with an internal. access modified, which means only classes within the assembly can access its properties (translated resource strings).
TOOL: This problem was solved bu Dmytro Kryvko and friends, who provide a way for .NET to only load a single assembly which code in other assemblies can reference to obtain translated strings. He reverse-engineered Microsoft's version of ResXFileCodeGenerator to change its class access modifier to public (from internal), and adding some enhancements along the way. It is available within page Extended Strongly Typed Resource Generator.
The down-side of this approach is that to make use of it, two COM objects must be copied onto and registered on every web server (by someone with administrator privileges).
Source is provided along with the COM object installer. It uses namespace "DMKSoftware.CodeGenerators". Author Dmytro (who works for Corrigo), has been actively maintaining the software since 2006.
Another down-side with this approach is that de-compilation and modification may need to occur with each new version of .NET which Microsoft puts out, since Microsoft may decide to change the error messages which needs to be ignored by the modified module, such as:
Visual Studio .NET 2008 introduces a new custom tool called PublicResXFileCodeGenerator to generate public resource class wrappers.
Is this is the approach with Visual Studio 2010 and .NET 4.0?
There are several strategies:
Luciano Sampaio from Brazil. part 2 Introduction
TOOL: GACutil.exe
The zip file also contains
a Globalization folder containing a .js file for each of the 137
(language + country) cultures .NET supports by default.
TIP: Immediately after download, rename the file to add the release date,
such as 2009_05_13 (for May 13, 2009).
In ASP.NET 2.0, to implicitly obtain localized text
specific to a particular page:
<asp:Label id=lblWelcome meta:resourcekey="lblWelcome"
Text="Welcome" runat="server">
</asp:Label>
You only need to set the values (Control.Property) of different fields for each control in the Visual Studio resource file editor.
In ASP.NET 2.0, to explicitly obtain localized text:
String welcome = Assembly.class.Welcome;
lblWelcome.Text = Assembly.class.Welcome;
When you see something like this in HTML returned from a ASP.NET server:
var __cultureInfo = '{"name":"fr-BE", ....
The EnableScriptGlobalization="true" property was specified by the developer so that ScriptManager makes use of the Language setting that Internet browsers send to servers in request headers.
By default it's "en-US" for English in the US. But some set it to other cultures for web sites which recognizes it. Facebook recognizes it.
The values are obtained from the Globalization folder of the Framework.
A Web Application Project contains an Assembly, which (among other things) specifies localized resource (.rex) files used in the project.
A Web Site Project does not contain an Assembly. Because of this,
A Web Site Project cannot use localized resource (.rex) files
specified in an assembly. ???
When a particular culture requires a different ordering of words than the neutral culture (English), a unique JavaScript file may need to be created for it. The ScriptManager automatically looks for a JavaScript file unique to a ResourceUICultures when it is specified with its child ScriptReference tag. The <asp:ScriptReference Assembly appears in the .aspx file's Design view within Properties viewr Behavior Scripts (Collection).
<Scripts> <asp:ScriptReference Name="MicrosoftAjax.js" Path="~/AjaxFramework/MicrosoftAjax.js" ResourceUICultures="fr"/> </Scripts>
Notice that these are in a AjaxFramework folder created in each project, and contains a Debug version copied from the AjaxFramework folder within C:\Programs\Microsoft.
Developers using this approach must remember that every time they make a change to the language-neutral (English) version of JavaScript, they must also duplicate (and test) those changes in each localized version.Additionally, there are debug versions of JavaScript files.
Thus, this is a typical cause of human mistakes and therefore error messages.
Related Topics:
Performance Testing
NT Perfmon / UNIX rstatd Counters
Mercury LoadRunner
Mercury Virtual Table Server (VTS)
Mercury WinRunner
Rational Robot
Free Training!
Tech Support
| Your first name: Your family name: Your location (city, country): Your Email address: |
Top of Page
Thank you! |