About BhashaIndia | Contribute | SiteMap | Register | Sign in to Windows Live ID
  Developers Patrons
Hindi Tamil Kannada Gujarati Marathi Telugu Bengali Malayalam Punjabi Konkani Oriya Sanskrit Nepali
Home > Developers > Tutorial > dotnet > Multilingual Applications Welcome Guest!

Developing Multilingual Applications

By Aparna Ravindran

The need for applications that span different cultures increased the demand for the creation of multilingual applications. The necessity for these applications originated due to the use of multiple languages across the globe and the different emerging cultures within a locale. Depending on the languages in a locale, the application needs to display the user’s locale-specific information in the locale-specific language. This is often referred as localization. Locale-specific settings include formatting of date, time, calendar specifications, and so on.

The .NET framework provides support for multilingual applications by creating resource files. These resource files allow you to specify the locale-specific settings. For each locale, you can create one resource file and specify the settings for that locale in the resource file. These resource files are then compiled into satellite assemblies and can be accessed in the applications by the classes provided by .NET framework.

The .NET framework allows you to create resource files in three different formats namely text file (.txt) format, .resx format and .resources format. After the creation of these files, you need to create the satellite assembly. Satellite Assembly can be created in two methods. One method is to use the AL.exe (Assembly Linker) utility and the other method is to use the VS.NET utility.
You can create the text format of the resource files, if the resource information is a string data. If the resources need to contain any embedded objects, then you need to create .resx file or .resources file. These two file formats can hold object(s) and string data. The text file format can be created using a text editor such as Notepad. The information will be specified in the form of key-value pairs.
The .resx file can be created by using the VS.NET IDE. To create a .resx file:
1. In the Project Menu, select Add New Item to display the Add New Item dialog box.
2. Select the Assembly Resource File option from the dialog box. This will add a new .resx file to your project.
You can specify the name and value of the resource information in the created .resx file.
You can also create a resource file to specify a particular locale. There are certain naming conventions to be followed while creating such files. They should adhere to the syntax specified below:
            < baseFileName >.< locale >.txt
            < baseFileName >.< locale >.resx.
For example, when you create a resource file for the locale “kn-IN”, the resource file name takes the form:
  • MyResource.kn-IN.txt – in case of the text file
  • MyResource.kn-IN.resx – in case of the .resx file
When the created resource file is compiled with ResGen.exe (Resource Generation File) utility, the output will be a CLR binary .resources file. This file can be embedded into a runtime executable or compiled into a satellite assembly.
Once the .resources file is created, you need to create the satellite assembly. Satellite assemblies are compiled DLL’s which contains only resource data. These assemblies are useful to load the data dynamically depending upon the current culture of your application. These are two methods to create the assembly.
One method is to use the AL.exe utility provided by the .NET SDK. The utility has the following switches:
/t: Represents the type of the output file
/culture: Represents the name of the locale for which the assembly is being created
/embed: Represents the name of the resource file that needs to be embedded into the assembly
/out: Represents the name of the output assembly generated
For example, if
  • the type of output file is a dll file,
  • the locale is ta-IN,
  • the name of the resource file is MyResource.ta-IN.resources and
  • the name of the output assembly is Myresource.resources.dll
then, AL.exe is invoked as,
             AL /t: lib /culture: ta-IN /embed: MyResource.ta-IN.resources /out:
             Myresource.resources.dll
The assembly thus created is a satellite assembly.
The alternate method of creating a satellite assembly is by using the VS.NET IDE. You can add a new resource file from the Add New Item submenu of the Project menu. After the resource information is stored, you need to set the Build option of the resource file to “Embedded Resource” in the Property window of the file. When the project is compiled, VS.NET automatically embeds the resource file into the assembly being generated.
Once the required resource files and satellite assemblies are created, the information from the resource files has to be retrieved to apply it to the GUI application. When a new form is created, you need to enable the Localization property of the form from its Property window. After enabling the Localization property, any controls that are added to the form will follow the same localization property. You can choose the language supported by the form using the Language property of the form. For each language chosen, a resource file will be created. You can store the resource information in those files.
Retrieving data from the resource files and satellite assemblies can be performed with the help of the ResourceManager class defined in the System.Resources namespace.
In order to retrieve data from the resource file, you need to create a .resx file by selecting Add New Item sub-menu of the Project menu. You then specify the file name as MyResources.ta-IN.resx and specify the key and value for the assembly. For example, you can create a resource file with the key and value as follows:
                Key : f1 ; Value : Sun Flower
                Key : f2 ; Value : Lilly.
After saving the file, you have to create the .resources file from the .resx file using the resgen.exe utility. You have to embed the resource file into an assembly using the al.exe utility. You then have to write code to read data from the resource files.
The following code shows how to retrieve data from the resource files using the ResourceManager class:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Resources.
 
namespace Resource
{
                    partial class Form2 : Form
                   {
                               public Form2()
                              {
                                          InitializeComponent();
                              }
 
private void button1_Click(object sender, EventArgs e)
                            {
                             ResourceManager rm = new ResourceManager("Resource.MyResource",
                             typeof(Form2).Assembly);
                            System.Threading.Thread.CurrentThread.CurrentUICulture = new
                            System.Globalization.CultureInfo("ta-IN");
                            label1.Text = rm.GetString("f2");
               }
}
In the above code, Resource.MyResource refers to namespace.resource file name. The GetString method of the ResourceManager class reads the value from the resource file and applies it to the Label control.
The following figure displays the output of executing the above code:
The following code shows how to retrieve data from the satellite assemblies using the ResourceManager class:
System.Resources.ResourceManager rm = new System.Resources.ResourceManager(Resource.Form2_ta_IN);
System.Resources.ResourceManager x;
System.Globalization.CultureInfo ci =  new CultureInfo("ta-IN");         System.Threading.Thread.CurrentThread.CurrentCulture = ci;
x = new ResourceManager("myresource.ta-IN", [Assembly].GetExecutingAssembly.GetSatelliteAssembly(ci));
Label1.Text=x.GetString("f1");
In the above code, you retrieve the value of the satellite assembly with respect to the culture specified by the ci variable.
Thus, the resource files created manually or by the VS.NET runtime allows you to store the locale specific settings for a particular form. When a form is localized to more than one culture, the application developed becomes a multilingual application.

Partner Profile | Privacy Statement | Why Passport | Testimonials
This site uses Unicode for non-English characters and uses Open Type fonts.
©2003-2007 Microsoft Corporation. All rights reserved.