Click here to Skip to main content
Licence CPOL
First Posted 19 Feb 2006
Views 53,941
Downloads 2,449
Bookmarked 31 times

Multilingual Application Made Easier in C#

By | 16 May 2006 | Article
This article focuses on how to work with a multilingual application
Sample Image - Multilingual_application.jpg

Introduction

This article explains how to make a multilingual application.

About the Sample Project

The sample project given in this article is an example of a Multilingual application. When speaking about multilingual applications, we need to manage resources specific to each culture. In my sample project, I have supported 5 languages, English, German, Spanish, Italian and French. This sample project supports switching to any of five languages at runtime.

To Do

It is very simple to make a multilingual application in C#. I used Visual Studio .NET 2003 to create my sample application. There is also a free IDE known as SharpDevelop which looks similar to Visual Studio .NET.

Now the Steps

  1. Do everything with the FormLayout (I mean design of your application).
  2. After the Designing of the form is done, the form now uses the default Language setting. Now build the application.
  3. Change the forms properties Localizable to true and set the properties Language to whatever Language you like to use.
  4. Change the Text of the Label, Button, Form and so on.. to the Language you have selected (isn't Limited only for Text property, you can also change layout specific to Language).
  5. Build the application.
  6. We are done now. Repeat steps 3 to 5 for the next language you wish to localize.

Now we have done something, but how do we check this work. We have to do something with the code.

Thread.CurrentThread.CurrentUICulture=new System.Globalization.CultureInfo("de")

The above code specifies the Currentuiculture for your application. This code has to be executed before initialization of the components. The string given inside the CultureInfo constructor ("de") specifies the language name  for the culture. Some of the culture names and languages are given below:

  • en - English
  • de - German
  • fr - French
  • it - Italian
  • es - Spanish
  • pt - Portuguese

How Does This Work

This section is the important one. When we set the form's localizable to true and build the application, Visual Studio .NET creates resources specific to the culture specified in the Language property of the form. Visual Studio .NET creates the resource file using resgen.exe. We can also create resources by using the following syntax:

resgen mytext.en-us.txt mytext.en-us.resources 
resgen mytext.en-us.resources mytext.en-us.resx

//This command reads a binary resources file mytext.en-us.resources and 
//writes an XML-based output file named mytext.en-us.resx 

Now the resources are created, but we need to link them to the application, so this is done by Visual Studio .NET using AL.exe (Assembly linker). We can also do it manually by doing this:

al 

/t:lib

/embed:mytext.en-us.resx 

/culture:en-us 

/out:Myapplication.resources.dll

You can find more about resgen.exe and al.exe in MSDN documentation.

Summary

I hope this article will help you. If you have any problem or find any mistakes, please let me know. You can email me at beniton@gmail.com.

Please don't forget to rate this article.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Beniton Fernando

Software Developer (Senior)
Raqmiyat LLC, Dubai
United Arab Emirates United Arab Emirates

Member

I m Beniton .I am a Developer currently working with Raqmiyat, Dubai since july 2007.I have been recently working on Visual C#.
 
My Interests
I like to read books,play cricket
 

http://beniton.googlepages.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionThanks a lot PinmemberPouriya.GH22:21 20 Sep '11  
GeneralMy vote of 4 Pinmembermarekbar21810:04 8 Aug '11  
GeneralMy vote of 4 PinmemberAlfredo De Jesus22:18 12 Jul '11  
GeneralMy vote of 5 Pinmembercbragdon4:57 30 Nov '10  
QuestionUser Controls PinmemberHORUS79316:07 8 May '10  
GeneralAutomation PinmemberSylvain_R2:32 12 Jan '07  
GeneralRe: Automation PinmemberBeniton Fernando2:54 14 Jan '07  
GeneralRe: Automation Pinmembervarandas797:59 28 Feb '09  
GeneralRe: Automation PinmemberPol7533:52 23 Aug '09  
General PinmemberMember #3212952:22 12 Jan '07  
GeneralLanguage Change At Runtime Pinmembertobias00417:32 25 Nov '06  
GeneralRe: Language Change At Runtime PinmemberBeniton Fernando18:25 25 Nov '06  
GeneralGerman Translation Pinmembertobias00417:07 25 Nov '06  
GeneralRe: German Translation PinmemberBeniton Fernando18:20 25 Nov '06  
QuestionWhat should I do next? PinmemberJP_Amber3:35 31 Jul '06  
AnswerRe: What should I do next? PinmemberBeniton Fernando20:28 5 Aug '06  

Hi
 
Before we start the application we need start the application we need to set the
 
Thread.CurrentThread.CurrentUICulture=new System.Globalization.CultureInfo("de")// Whatever language we like to set
 
It means that the first line of the Constructor of the particular Form Should be the above line.
 
public Form1()
{
Thread.CurrentThread.CurrentUICulture = new new System.Globalization.CultureInfo("de")// Whatever language we like to set
//Then initailise your components
}
If you setting your language Dynamically you need to restart your application
with Language you set.It will be simple if we store the Language option in a file and Read those options while start the application
 
I guess this will solve the problem
 
With Regards
D.Beniton Fernando
 

 

 
Be still and know - Osho

GeneralRe: What should I do next? Pinmemberpeitor21:52 20 Aug '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 17 May 2006
Article Copyright 2006 by Beniton Fernando
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid