Multilanguage Application Development Employing VS

Multilanguage Application Development Employing VS

Multilanguage application development employing VS.NET

Introduction
Think of localization in the planning and design stage itself. Use Unicode for all the data, variables, text, etc. Put all the language dependent text like menus, button text, label text, messages, text for dialog boxes, error messages, help files, etc. in resource files. VS.NET creates the required resource DLLs while compiling. If employing database, then use Unicode data type in the database. In SQL Server this is accomplished by defining the data type as nchar, nvarchar and ntext. If it is a web-based application, then use ASP.NET for developing. It will be advantageous to use dynamic fonts (.EOT files) for a web-based application so that the end-user need not download the fonts. Remember to instruct the end-user to use Windows XP or 2003 as the platform and enable Indic via control panel. This will allow the user to enter Indic text into the

application, if needed.

Applications created using .NET falls into two categories, viz., windows and web applications. Both of them support localization. Visual Studio.NET IDE has rich support for resources. In this example we will create a multilingual Windows application employing VB.NET.

Getting started

Most important guideline for any multilingual development is that all language dependent info should not be hard-coded. They have to come from resource files. Buttons, menus, labels, etc. should not have any text on them. We will have to load the text from the resource files at run-time based on the selected language.


Take a look at the Windows form given above. None of the buttons and labels has any text on them.
When a Windows application is created, every form automatically gets an XML resource file (*.resx). First thing to do is to set the Localizable property of the Windows Form to True so that the VS.NET IDE comes to know of your intention to create a multilingual application.

After the Localizable property is set to True, we can add as many languages as we want. Simply select the language from the available list of languages. As we select the language property, the VS.NET IDE keeps adding the resource files for the languages selected one .resx file for each language selected.

If we take a look at the project explorer, we will see the additional resource files with a tree structure. In this particular case, the main VB form has the name frmWelcome.vb. The resource files have names frmWelcome.en.resx for English, frmWelcome.hi.resx for Hindi, frmWelcome.kn.resx for Kannada and so on.

By double-clicking on this file, the resource editor opens up. All language dependent texts can be added here. This can be edited in data or XML view.

A satellite assembly will be generated for each and every language that your application supports. These satellite assemblies are kept outside the binary for the application. There will be one resource file for each language to be supported. The folder structure of the binary and the resource DLLs after installing the application looks like this-

In the above example, MultiLanguage.exe is the main binary of the application. This application supports English(en), Hindi(hi), Kannada(kn), Tamil(ta) and Telugu(te) languages. Each language specific resource is kept in the respective folder -kn for Kannada, hi for Hindi, en for English, etc.
The .NET international support is concentrated across a few namespaces within the overall framework. There are three important namespaces used in connection with Globalization/Localization.

System.Globalization – namespace contains classes that define culture related information including the language, country/region, the calendars in use, and the format pattern for dates, currency and numbers and sort order for Strings.

System.Resources – namespace provides classes and interfaces that allow developers to create, store and manage various culture-specific resources used in an application. One of the most important classes of System.Resources namespace is the ResourceManager class. The ResourceManager class allows the user to access and control resources stored in the main assembly or the resources in satellite assemblies.

System.Text – namespace contains classes representing ASCII, Unicode, UTF-7 and UTF-8 character encodings. Abstract base classes for converting blocks of characters to and from blocks of bytes; and a helper class that manipulates and formats String objects without creating intermediate instance of strings.

Hence, any program that needs to be supporting multiple language should have these statements in the beginning-

privatevoid SetUICulture(string culture)

{

System.Resources.ResourceManager rm = new

System.Resources.ResourceManager(this.GetType());

try

{

System.Threading.Thread.CurrentThread.CurrentUICulture = new

System.Globalization.CultureInfo(culture);

lbl_Name.Text = rm.GetString("lbl_Name.Text");

lbl_Age.Text = rm.GetString("lbl_Age.Text");

}

Catch(Exception ex)

{

MessageBox.Show(ex.Message);

}

}

privatevoid tamilToolStripMenuItem_Click(object sender, EventArgs e)

{

SetUICulture("ta");

}

privatevoid hindiToolStripMenuItem_Click(object sender, EventArgs e)

{

SetUICulture("Hi");

}

In the above code, the parameter "culture