Making an existing program multilingual

mjohnson3091

Freshman
Joined
Aug 10, 2004
Messages
31
Location
Lancashire, UK
Hi all,

I'm just looking for some advice on the best way to go about making a current c# application multi-lingual.

Currently all the text for controls captions and messages are coded in to the application, so I was wondering what the best approach would be.

My thoughts were to store all the strings in a database table (as the application uses a DB anyway) and read them in at start up into a class and then use them that way (ie. cmdOK.caption = Lang.OK;)

The problem I have with that is how to go about extracting all the text from within the code. Any suggestions other than a manual approach??

Alternatively, as this hasn't taken place yet, I'm open to other suggestions.

Please take into account that this application is running on a mobile device.

Thanks in advance for any suggestions/advice.

Mark
 
.Net itself has a fairly reasonable localisation mechanism via the use of resx files. In visual studio itself if you select a form and look under it's properties there is one calle 'localisable' - setting this to true will move all localisable content from the ui into this .resx for you.

If you have any strings hardcoded into the actual code files then this can get a bit nastier to move into .resx files, however http://www.codeplex.com/ResourceRefactoring can be a big help in getting this task done.

Once all the basics are done you can then add new languages via these .resx files (resgen.exe installed along with VS can make handling the string conversion easier, winres.exe can make designing the ui easier).

One good thing is that all languages apart from the default one get compiled in to seperate dlls so these can be built outside of VS and created / deployed as and when there is a need.
 
Thanks for that, I'll have a look into that method.

When you mentioned about building the resource files into separate DLL's I'm guessing that these can then be managed in code, for example if the user selects a different language from the application itself as opposed to the machine Locale setting?

I'm just thinking on the mobile devices, the default Locale would be English, but they may have Polish or German operators for these devices, so they would need to be "hot-swappable" so to speak.

Thanks,

Mark
 
It is based on the locale you specify - this would normally be done in the Main method of your application if using C# or the MyApplication_Startup if using vb in vs 2005 or later.

To use the default locale it would be as easy as
Visual Basic:
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
to use a specific culture that would just be something like
Visual Basic:
Thread.CurrentThread.CurrentUICulture = system.Globalization.CultureInfo.CreateSpecificCulture("de-DE")
 
Back
Top