96

I've been looking into making applications suitable for multiple languages in C# since I need to work on a small project where this is the case. I have found basically two ways to do this:

Set a form's Localizable property to true, set the Language property, fill all the labels and such, and you're 'done'. The major drawback I see in this is: how to make other stuff which is not part of a form ready for multiple languages (e.g. pop-up windows, log files or windows, etc).

Create a resource file, for example 'Lang.en-us.resx' and one for every language, for example 'Lang.nl-nl.resx' and fill it up with Strings. The IDE seems to generate a class for me automatically, so in the code I can just use Lang.SomeText. The biggest drawback I see in this is: for every form I need to set all the labels and other captions myself in the code (and it doesn't seem data binding works with these resources).

I'm sure, however, that there are other methods to do this as well.

So, what is the best practice? What's the easiest for small applications (a few forms, database connection etc) and what scales best for larger applications?

Mihai Limbășan
  • 64,368
  • 4
  • 48
  • 59
  • 3
    I have noticed, that not constructive (or other "not valid for SO" type of questions) are one of the most valuable questions :) This one also is a good questions (I think votes prove that) Here is a good demonstration on how to use multi language add-in for multi language support https://www.youtube.com/watch?v=SNIyP1QQdVs – Prokurors Jun 25 '15 at 08:33
  • 1
    It's so hard to piece together all the fragments of knowledge around the internet sometimes, and I find this question invaluable right now. Surely there are times when closing soft questions is less constructive than leaving them open, and I'd think this is one of those times. :) –  Mar 31 '16 at 02:11

3 Answers3

21

I have always used resource files for multi-language applications.
The are many articles on the web explaining how to use them.

I have used two different ways:

  • A resource file per form
  • A global resource file

The resource file / form, is easier to implement, you only need to enter the values in the resource file, but I find this approach harder to maintain, since the labels are dispersed throughout the application.

The global resource file allows you to centralise all the labels (images etc.) in one file (per language), but it means manually setting the labels in the form load. This file can also be used for error messages etc.

A question of taste...

One last point, I write programs in English and French, I use "en" and "fr" and not "en-US" and "fr-FR". Do not complicate things, the different dilelects of English (American, English, Australian etc) have few enough differences to use only one (the same goes for French).

ThatBloke
  • 513
  • 4
  • 14
  • 2
    You have to worry about dialects sometimes. For instance the Chinese characters are completely different in Traditional Chinese (Taiwan) versus Simplified Chinese (mainland China). – MarkJ May 06 '09 at 22:51
  • 1
    @MarkJ [MSDN documentation](http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(v=vs.80).aspx) mentions that Traditional Chinese and Simplified Chinese are not dialects (country/region) but neutral cultures. Msdn: "A neutral culture is a culture that is associated with a language but not with a country/region. A specific culture is a culture that is associated with a language and a country/region. For example, "fr" is a neutral culture and "fr-FR" is a specific culture. Note that "zh-CHS" (Simplified Chinese) and "zh-CHT" (Traditional Chinese) are neutral cultures." – broadband Feb 03 '14 at 10:03
  • I recently did this with the help of [link](http://www.codeproject.com/Articles/15248/Globalization-of-Windows-Applications-in-Minute) , 2 steps not mentioned there : 1. Click all the .resource files and set "Build Action" property to "Content". 2. Click all the .resource files and set "Copy to Output Directory" property to "Copy Always". – Sourav Jun 26 '15 at 06:05
  • 1
    @Kiquenet For a complete (with code) answer including .NET wide support, see: https://stackoverflow.com/a/35813707/2901207 – CularBytes Mar 01 '18 at 20:26
10

I recently wrote a program with both German and English language support. I was surprised to find out that if I simply named my english resources LanguageResources.resx and my German resources LanguageResources.de.resx, it automatically selected the correct language. The ResXFileCodeGenerator took care of it all for me.

Note that the fields in the two files were the same and any not yet entered German fields would show up in the application as English as the most non specific file language wise is the default file. When looking for a string it goes from most specific (ex .de-DE.resx) to least specific (ex. .resx).

To get at your strings use the ResourceManager.GetString or ResourceManager.GetObject calls. The application should give you the ResourceManager for free.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
Rick Minerich
  • 3,078
  • 19
  • 29
6

For the benefit of others who may come across this (1+ years after the last post), I'm the author of a professional localization product that makes the entire translation process extremely easy. It's a Visual Studio add-in that will extract all ".resx" strings from any arbitrary solution and load them into a single file that can be translated using a free standalone application (translators can download this from my site). The same add-in will then import the translated strings back into your solution. Extremely easy to use with many built-in safeguards, lots of bells and whistles, and online help (you won't need it much). See http://www.hexadigm.com

Larry
  • 796
  • 6
  • 13
  • 1
    This should be added as native function to visualstudio! Great software! – Caverna Aug 09 '15 at 14:16
  • Thanks very much (appreciated). I would have agreed with you before starting the product (about 10 years ago) but if MSFT implemented it today it would put me out of business :) – Larry Aug 10 '15 at 17:12