C# Tips and Tricks >  Globalization in 20 minutes using C #


 

Globalization of Windows Application in 20 Minutes 

Prelude

There was once a time when multiple language support to a windows application used to be a three to six months call, but with the advent of .Net not anymore. Here is a 20 minutes crash course for globalization / Localization of a windows application. I think you'll find it as useful as I do. 

Globalization in simple terms means enabling an application so that it works in different national, similar to how a global company operates in different countries. For a windows application globalization means, it is intended for worldwide distribution. There are two aspects of the Globalization:

  • Internationalization : Enabling the application to be used without language or culture barriers, i.e. language and cuture information comes from a resource rather than hard coded in the application  
  • Localization : Translating and enabling the product for a specific locale. Based on the resource file translating the application into that language and culture

Target

  • Modular design: Code Once Use Everywhere (COUE), this is the prime feature which is needed when you globalize an application. All anyone should do is to convert any user interface output/message box /labels text etc, to something like  frmMain.RM.GetString("10001"), No culture information or resource manager initialization again in all the forms or anywhere else
  • Default language: Saving and retrieving the default language selected by the user in registry 
  • Features: How to take care of  date/time , multiple forms , images etc
  • Reusability: Minimum number of effor when you a dd a new form to the application
  • Extensibility: Support of multiple language, French, Spanish and English using resource files for each

To hold your interest here is how it looks

 

Acknowledgement

 My humble acknowledgement to my boss who gave me a 6 days deadline, for globalization of an application we have been working on for an year.

Why not .Resx approach for small /medium sized application

i got a number of emails asking why not use the .resx approach for each forms well here is few of the reasons, i prefer a single resource file compared to multiple .resx files for each form

Three simple reasons

1. Maintainability

Assuming you are taking .resx files approach

Take a simple scenario, By mistake you have a wrong translation for a "Submit" button for a say german language. The original translation is "Einreichen" but you initially missed the last n and now you have "Einreiche" instead of "Einreichen" for submit button through out your application

What you can do to resolve this,

a. You have to go to each forms and change the resource file of the form
b. Compile the exe again creating the german dll and redistribute the whole exe with setup including the new dll

On the other hand if you use a single resource file as in the article ,
Each "Submit" in all the forms translates into something like
ResourceManager.GetString("101")

If the translation is wrong just -

1. Update the initial german text file
2. Resgen it and create a resource file
3. Over write your existing resource file by the updated resource file

you are done. Redistribution needs just the light weight resource file and you EXE will automatically update the submit button every where

2. Extensibility

You have to add another language say latino.resx file approach go to each form create resx file for Latino compile and create latino dll

With Single Resource file approach create another text file with latino translation as shown in example above Resgen it and Add a menu option for Latino you are done. You can have a latino menu option even earlier and add teh resource file later you won't even need to re compile

3. Dynamic UI changes


With resource file you can have a drop down menu instead of the radio button in the example and change the complete UI on the fly to whichever language you fancy
With .resx and dll approach you have to start the application with that localized dll
i think you might be able to dynamically change the UI but it will be much more complicated process.

Another not that important reason is, Resource file approach create light weight .Resources files where as .resx creates dll for each language.

If want to go by the standard approach you can definetly get better results but not as fast as this approach will give you

Article History

  • August 20 2006: First Published
  • September 01 2006: Added comparision with .Resx approach
Comments / Suggestions


screen  Add a Comment 
Subject  User  Date 
Last Visit: 1:13:11 PM, Friday, November 21, 2008


You can also reach me at: here

Rate This Page