October 22, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Build a Localized Form that Speaks the User's Language

  • July 22, 2004
  • By Mark Strawmyer
  • Send Email »
  • More Articles »

Form Sample Output

Figure 1 shows the output of the sample form. When you press either of the buttons, it displays some simple message boxes.

Figure 1: Default Locale (English)

Editing Resource Files

Resource files are simple text-based files that you can edit with a simple editor like "Visual Notepad" (as I often affectionately refer to good old Notepad). However, Visual Studio .NET makes creating resource files through the IDE easy. It also has a utility called winres.exe that allows resources to be edited in a lightweight editor that cannot change code. Because I'm all about taking the path of least resistance, I'll create the resource files through the Visual Studio .NET IDE. Here is the basic recipe for creating a localized form using the form from above:

  1. Set the Localizable property of the form to true using the properties window.
  2. The form has a Language property as well. To enter the settings for a specific locale, you set the Language property to the desired locale. (For this example, I set the Language property to German (Germany).) Now, Visual Studio is ready for you to enter your locale-specific settings. Go through each control and change the properties as desired. Here are the changes that I made for the German (Germany) locale:
    1. Form1.Text = Deutsche Anwendung
    2. NameLabel.Text = Ich heisse:
    3. LangQuesLabel.Text = Sprechen sie Deutsche?
    4. GoBtn.Text = Gehen
    5. HelpBtn.Text = Helfen
  3. Rinse and repeat, err, I mean repeat Step 2 for every other locale you wish to set up. As you switch between the locales you have set up, you will see the form automatically change to match your configured settings, like when I changed the locale back to English (United States).
  4. Now, it's time to compile the form. Once you have compiled, you should see an additional set of folders underneath the bin\Debug directory that contain locale-specific information. The form itself also will have several additional .resx files generated for it.
  5. Now, test out your application. You could go into the Control Panel and change the locale information on your machine. If you're anything like me, however, you may not be smart enough to get it all put back. A safer way to test is setting the CurrentUICulture property of your application's thread to specify the desired culture at the start of the Main method. For example, I added System.Threading.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");.




Page 2 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel