Friday, June 26, 2009

MultiLingual (in different speaking languages) support in your .NET Application

I am supporting a project which is in market, developed by our company. All of a sudden our client appeared and asked for multi-language support for the software. i was very much confused on how to deliver that. But later i found that with the Help of VS.NET it is very much easy to deliver any application with multiple language support.

So, i decided to write this article on my blog about how to create a Multilingual application using .NET, and also what to consider while developing a Multilingual application.

selection of the database is one of the factor for saving data as user has entered. MS SQL Server is one of the option that can be used, as the developement evvironment is Windows and we are using VS i suggest SQL Server 2005 or above as a better option.
SQL Server provides to dataTypes nvarchar and nchar which can used to store data in different language format.

inorder to use the Localization in your application make reference to two namespaces

System.Threadig and System.Globalization

Globalization is the namespace that provides feature for setting the Current Cultur as per user desire.

when you go for localization you should alos consider the input language what i mean to say is that if your providing your application in french language then you should proivde provision for inputing data in french language.

inorder to provide the facility of inputing data in specific language you must have those languages installed if not you can install them. if you can install languages from
Start->Settings->Control Panel->Regional and Language options
Select Language Tab -> Select Details there you can see the list of languages installed and you can add New languages.

for my example i am checking for french language installed on my machine
foreach(InputLanguage Language in InputLanguage.InstalledInputLanguages)
{
if(Language.LayoutName=="French")
{
InputLanguage.CurrentInputLanguage = Language;
break;
}
}

Now lets create Step-by-Step Application for US and French Language
step 1. Create a Blank Windows Applciation.
step 2. Select Form1 that is your default Form, make its Localizable property to true and make its Language property to default, which is already by default.
step 3. Drag and drop a button on the form and set its Text property to "Click Me", Save the application
step 4. Select Form1 and Set it Language property to French (France)
step 5. Select button1 set its Text Property to "Cliquez-moi"
step 6. Save and build your application.
step 7. press F5 to run the application, you will find the button displaying the button1 text as "Click Me" it is because your default language is "US" you need to change the Culture. Inorder to do that, Add following code before callingInitializeComponent();

Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");
and then press F5 you will see your application displayed French language.

The main magic behind is the resource file that VS studio creates when you set the Language option for your form. Go to Solution explorer and click on Show All Files you will find file named form1.fr-FR.resx double click on it. see the content VS has created mapping data for you. Whenever you change your Culture info your application will look for appropriate file. If found it will look for the actual data and will display the mapped data. If it is not found it will display the default language i.e. "US"