Click here to Skip to main content
15,881,715 members
Articles / Desktop Programming / Windows Forms
Article

Multilingual Application Made Easier in C#

Rate me:
Please Sign up or sign in to vote.
3.64/5 (31 votes)
16 May 2006CPOL2 min read 125.9K   7.5K   43   21
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.

C#
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:

C#
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)


Written By
Technical Lead Calsoft Labs, Chennai
India India
I m Beniton .I am a Developer currently working with Calsoft Labs Chennai, India. I love reading books, watching movies, playing cricket and spending time with my family.

Comments and Discussions

 
Questionwant to make project in multilanguages in c++ (ATM machine software) college project Pin
Member 149822962-Nov-20 20:03
Member 149822962-Nov-20 20:03 
QuestionCreate multilingual website in MVC Pin
Member 1321886517-Jul-17 7:06
Member 1321886517-Jul-17 7:06 
QuestionChange language in gridview Pin
Member 117486807-Jul-15 0:14
Member 117486807-Jul-15 0:14 
QuestionGreat Pin
BaoSaka31-Jan-15 18:23
BaoSaka31-Jan-15 18:23 
QuestionThanks a lot Pin
Pouriya Ghamary20-Sep-11 22:21
Pouriya Ghamary20-Sep-11 22:21 
GeneralMy vote of 4 Pin
marekbar2188-Aug-11 10:04
marekbar2188-Aug-11 10:04 
I've been looking for an automatic language change method after components initialization...
GeneralMy vote of 4 Pin
Alfredo De Jesus12-Jul-11 22:18
Alfredo De Jesus12-Jul-11 22:18 
GeneralMy vote of 5 Pin
cbragdon30-Nov-10 4:57
cbragdon30-Nov-10 4:57 
QuestionUser Controls Pin
HORUS7938-May-10 16:07
HORUS7938-May-10 16:07 
GeneralAutomation Pin
Sylvain_R12-Jan-07 2:32
Sylvain_R12-Jan-07 2:32 
GeneralRe: Automation Pin
Beniton Fernando14-Jan-07 2:54
Beniton Fernando14-Jan-07 2:54 
GeneralRe: Automation Pin
varandas7928-Feb-09 7:59
varandas7928-Feb-09 7:59 
GeneralRe: Automation Pin
Pol75323-Aug-09 3:52
Pol75323-Aug-09 3:52 
GeneralNo Subject Pin
Sylvain_R12-Jan-07 2:22
Sylvain_R12-Jan-07 2:22 
GeneralLanguage Change At Runtime Pin
tobias00425-Nov-06 17:32
tobias00425-Nov-06 17:32 
GeneralRe: Language Change At Runtime Pin
Beniton Fernando25-Nov-06 18:25
Beniton Fernando25-Nov-06 18:25 
GeneralGerman Translation Pin
tobias00425-Nov-06 17:07
tobias00425-Nov-06 17:07 
GeneralRe: German Translation Pin
Beniton Fernando25-Nov-06 18:20
Beniton Fernando25-Nov-06 18:20 
QuestionWhat should I do next? Pin
JP_Amber31-Jul-06 3:35
JP_Amber31-Jul-06 3:35 
AnswerRe: What should I do next? Pin
Beniton Fernando5-Aug-06 20:28
Beniton Fernando5-Aug-06 20:28 
GeneralRe: What should I do next? Pin
Peter Gfader20-Aug-08 21:52
Peter Gfader20-Aug-08 21:52 

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

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