Hi guys,
When you create a desktop application
or a mobile app you can’t stick to the one language or else one language
edition, obviously you can limit your app, but if you look at the commercial
aspect that limitations directly impact your market. Today we have facilities
to open our product to the world through different apps market like the Google
apps market, Apple App store and so many different web platforms. Usually if you want to introduce your product
to world largest market like China, Russian you should adapt to their language.
Otherwise, you can’t give a competition to your competitors.
In this post I’ll explain how to
internationalize your product. Internationalization can be categorized as a two
different way,
What is the culture?
The International standard
organization (ISO) introduces some standards to identify culture, according to
countries in the world, as an example United State of America culture define as
(en-US), culture definition formatted as a Language code – Country Code.
Create globalized app using .Net
frame work (C#)
Let’s create a small
app which is display current date, But the thing is when we display current
date, that date format is formatted according to your PC settings. But my
target generates date according to user choice. I’ll provide user to 3 choices,
‘Sinhala’, ‘English’ & ‘French’. In order to do that I’ll provide a combo
box to select language, three labels to named content. Here’s the draft
interface of my app.
For the internationalization process,
we must do some pre-steps. Above interface diagram labeled 3 ‘label fields’ as
a label, label1 and label2. After that we can easily access thought the names
which are assigned to the label fields. Another thing is, we need to import
name space called, ‘Globalization’. After that we can do the
internationalization process. According to this scenario, we need to customize
the app allowing three different languages. I’ll explain how doing the
internationalization process to the one language.
I explained the internationalization
process can be divided into two sub categories, first one is globalization.
Globalization, convert numbers, date time format & currency format
according to specified culture. In our application label filed named ‘label’
represent a date. In order to convert date format. We need to pass the language
code – country code as the current culture.
using System.Globalization;
System.Threading.Thread.CurrentThread.CurrentCulture = newSystem.Globalization.CultureInfo("si-LK"); // Sinhala - Sri Lankan format
label.Content = DateTime.Now.ToLongDateString();
System.Threading.Thread.CurrentThread.CurrentCulture = newSystem.Globalization.CultureInfo("si-LK"); // Sinhala - Sri Lankan format
label.Content = DateTime.Now.ToLongDateString();
The second category is localization,
convert label fields, tool tips, text boxes according to specified culture
called as the localization. In order to convert ‘label1’ and ‘label3’ according
to specified language we need to define the resource file first.
In solution explore, go to the ‘proprieties’
and copy ‘Resource.resx’ file and paste it into the same folder. Then rename it
as ‘Resource.si-LK.resx’. After that open the ‘Resource.si-LK.resx’ file, you
can see the table separated into three columns as the ‘Name’, ‘Value’, ‘Comment’.
Now you can fill the table according to your requirement. If you are needing to
add another language simply add another Resource file and define according to previous
steps. Here’s the table.
Finally, we can assign the values
which are defined in the ‘Resource.si-LK.resx’ to the labels. Please make sure
when you define Resource file, define the by default values inside the ‘Resource.resx’
file. Previously we changed the Current culture in the application. Now we have
changed the Current UI culture of the app. After that we can assign to the
label contain using values which is define inside the resource file.
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("si-LK");
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("si-LK");
label.Content = DateTime.Now.ToLongDateString();
label1.Content = WpfApplication4.Properties.Resources.day;
label3.Content = WpfApplication4.Properties.Resources.selectlanguage;
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("si-LK");
label.Content = DateTime.Now.ToLongDateString();
label1.Content = WpfApplication4.Properties.Resources.day;
label3.Content = WpfApplication4.Properties.Resources.selectlanguage;