Localization in VB.NET
Posted On July 13, 2015 by Anish S filed under Enterprise
Have you ever thought of using Microsoft Word, Outlook Express or some other applications in your mother tongue? Application developed few decades earlier had the English interface so that the users, who speak English, feel comfort with it. But think about the users who don’t know English. Can’t they apply computers for their routine works? The solution is to develop world-ready applications. What does World-Ready application means?
The users should be capable of customizing the applications based on their mother tongue or culture. For an instance, consider the usage of an Inventory System in a Super market. The supervisor of the shop works with the English interfaced software. If the salesman who does not know English and knows only Tamil, he/she should be able to work on that same Inventory Application with the Tamil interface.
If your application is to be shipped to different parts of the country or even to other countries, this makes a great sense. Countries have their own languages and cultures. The people should be able to work on the applications tied with their culture.
Developing such applications requires variety of issues to be considered from the design phase. The two main steps to be understand while designing such world class applications are Globalization and Localization.
This is the first step of developing culture based applications. According to Microsoft, a globalized application can correctly accept, process, and display a worldwide assortment of scripts, data formats, and languages. But the language of the user interface remains unchanged. That is, you have not localized the application for another culture/locale.
An intermediate step prior to localization is a process known as localizability. Localizability is about ensuring you have enabled a globalized application for localization by separating the resources requiring localization from the rest of the application. Proper localizability results in source code you will not have to modify during localization.
The final step, localization, is the process of customizing your application for a given culture/locale. Localization consists primarily of translating the user interface.
- Create a new VB.NET Windows Application in Visual Studio.NET
- In the Properties window, set the form's “Localizable” property to “true”. The “Language” property is already set to “(Default)”.
- Design the form as given below (Fig 1)
- Set the form's “Language” property to the language u wish. For instance I choose "Tamil (India)".
- Save the solution.
- Click the "Show All Files" button in Solution Explorer. The resource files appear underneath Form1.vb. Form1.resx is the resource file for the default culture, which will be built into the main assembly. Form1.ta-IN.resx is the resource file for Tamil as spoken in India. In addition, you will see files appear named Form1.ta.resx. Visual Studio automatically creates these files in order to work around a limitation in Visual SourceSafe.
- Open the Form1.resx file by double clicking it and you could see some entries there. Now you are going to add some entries to that list. These entries are the resource text which we are going to use it in our application.
- Now open the Form1.ta-IN.resx file and add the entries with the same name as used in the Form1.resx file. Change the value in the chosen language. Here in the Fig 4 I have used Tamil words. I use Windows Character Map utility to type in the Tamil words and then copy it to the resource file.
- In the Code Editor, add the following code at the beginning of the module, before the Form1 declaration:
Dim lang As New ResourceManager(GetType(Form1))
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
MsgBox(lang.GetString("Msg"), , Me.Text)
Private Sub cmdChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChange.Click
Thread.CurrentThread.CurrentUICulture = New CultureInfo("ta-IN")
cmdOK.Text = lang.GetString("OK")
cmdChange.Text = lang.GetString("Change")
Label1.Text = lang.GetString("Wish")
Me.Text = lang.GetString("MeTitle")
Run the Application by pressing F5 or select “Start” from the Debug Menu. Now you could see the Application running on your Desktop as shown in the Fig 1. Click the “Change” button to change the Language to Tamil.
Click the OK button and u could see the following output. The language of the message box text depends on when you click it. If u press the OK button after clicking the CHANGE button you will the message in Tamil, else it will be in English.
You can also include more language by selecting the required language in the “Language” property of the Form. The language can be switched by using the appropriate resource file. I use a flag variable to check and to switch between languages. Try it on your own.
Menus can be also localized as shown below. This is a typical example of a “About” Menu.
For queries, suggestions & feedbacks mail him on firstname.lastname@example.org