Localizing a Windows Form

Always have a question mark about how to do localization for a windows Form application. So taken this challenge and here the steps goes

1. Create a Windows Forms Project.

2. Set the Localizable property of Form to True.

3. A resx file is created per window form.

4. Add Control Name.Text as Name and its value to “My Form”. The convention of the name is Control Name.Property Name

5. A resource file generated per language i.e. if you would like to support 5 languages then need to have 5 resx file. Each one following MS specified naming convention.

6. Initializes the ResourceManager
ResourceManager resMgr = new ResourceManager(,
Assembly.GetExecutingAssembly());
Here while providing the name of the form provide the fully qualified name of the form class name i.e. with namespace.

7. Initializes the Culture based on the language selected, assumming there is config file where the locale is set
locale = ConfigurationManager.AppSettings[“LOCALE”];
if (locale == “DEFAULT”)
Thread.CurrentThread.CurrentUICulture = CultureInfo.InstalledUICulture;
else
Thread.CurrentThread.CurrentUICulture = new CultureInfo(locale);

8. Now use the ResourceManager to read the read the corresponding culture string

this.Text = resMgr.GetString(“<Control Name>. <Property Name>”, Thread.CurrentThread.CurrentUICulture);
The above set the Text property of the Form to the corresponding localized string.

Yuppppieeeeeeeee the form is localized.

The namespaces to refer
using System.Threading;
using System.Globalization;
using System.Resources;

The Links for help
Link 1
MSDN Link

Advertisements

3 Responses

  1. DATA MODUL

    Thank you for your post!

  2. GE Sensing

    Thank you for your post!

  3. Brunschwig & Fils – Good Design Is Forever

    Thank you for your post!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: