Page 1 of 1

Making multilingual applications actually not that hard in .NET

#1 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Posted 16 November 2008 - 03:03 PM

Not everybody knows how to speak and read English, and translating your application into multiple languages might just get it a few more customers. Visual Studio (including the express editions) has built-in multilingual features, and here i will teach you how to use them. Before you start, there are a few things you need:

1.
A completely finished English language application (or at least mostly finished, as making changes once you have enabled multilingual support can be a pain in the ass)

2.
An online translator (I use Windows Live Translator)

That's all. If you haven't already, open up your application in Visual Studio. Open up the form you want to make multilingual in the designer (probably your main form). Now, if Visual Studio takes as long to load on your computer as it does on mine you might as well go to McDonald's and get yourself a Big Mac while you wait. Anyway, in the property pages for your form, look at the "Design" category (if you are in categorized mode). There are two properties under that category we are concerned with: Language and Localizable. First, set the Localizable property to true. That's the first step. Look at the Language property; it should have a value of "(Default)". Whenever you change the language property, it will create a resource file in the form of a DLL that will hold all the information for the form that you want to be language-specific. Thus, when you change the language property, any changes you make to the form will only appear when the form is in that language. If you are editing the form and the "(Default)" property is chosen, the changes you make will affect all languages, however. If you are planning to distribute your application with an English translation, which i assume you are, change the Language property to "English". Your form will reload itself, and a resource file will be created for that language in a directory in your debug and release folders called "en", which is the two-letter ISO language name for "English". Now, any changes you make to the form will only appear when the form is set to display in English. Now, i assume since you made your application in English, you have no changes to make. However you still needed to select "English" for the language property so a English resource file would be created for your project. Now, you can get to the translating. Go to the language property, and select one of the language you want the form to be translated into. The form will reload itself, and the changes you made while the English property was selected (if you made any at all) will not be there, because they are stored not in the designer code, but in the English resource file. Now, a new resource file has been created for the language you just selected, and it was modeled after how the form last looked when the language was set to default. Now, here's the hard part. Visual Studio does not have a built-in translator or anything like that, so for every control that you want to appear different in this language (probably the text is all you want to change, but the language resource files will also store information for all of the other properties), you must change. To change the text of the control into another language, just translate it with an online translator like i said you would need and re-enter it in the control's Text property. Then, do the same for all the languages you want your form translated into (which will probably take hours depending on the size of your application), and also do the same process for all the forms in your application you want to appear in multiple languages.

There, now you have a nice multilingual application. However, what's the good of having a multilingual application if you can't let the user select the language? Now we will add in that part. There are two ways you can go about doing this:

1.
When your application runs, it will automatically decide which language resource file to load the form off of based on the culture information of the current computer. However, that does not let the user decide what language he wants, but instead the application will decide what language it wants to be shown in. If you want to do it this way, your done.

2.
If you want, you can override the automatic language-selecting feature and let the user manually decide what language he wants himself. I prefer this way personally.

Like i said, if you want to trust that the .NET auto language selecting feature will work, your done. Otherwise, i will explain exactly how to do #2. Now, to override the auto language select, you can change the language manually with the System.Threading.Thread.CurrentThread.CurrentUICulture property. For example, to change the language to German, you would use
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");

("de" is the two-letter ISO language name for German, since "German" is pronounced "Deutsch" in German.)

However, you must assign the language using that property before the main form has loaded, and you cannot modify it once the application is running. Basically, there are two places you can change that property: in your application's Main procedure before the Application.Run() call has been made, or in your form's constructor before the InitializeComponent() method has been called.

You can also get the current two-letter ISO language name of the currently used language using the System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName property. For example
System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName == "en"
would return a value of weather or not English was the current language.

Well, now you know all you really need to. If your going to go with method #2, you should probably put some sort of form that will let the user choose what language he wants. Then, when your application exits, you could store the current two-letter ISO language name in an ini file or the application's settings so the application knows what language to use next time.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1