2

I am writing a program in C# for a Windows CE device and would like the application to be translated according to a language setting in the application itself.

I have already read some articles about localisation using resource files and translating forms using the 'Localizable' and 'Language' properties. From what I have read I understand that this type of form translation works with the OS language setting (correct me if I am wrong).

Now I am looking for a way to do the form translation dependent on my own in-program language setting, preferably using resource files.

I have already thought of doing this translation in the Load event of each form but maybe there are other solutions or best-practice for this. Any help is appreciated.

jdetaeye
  • 183
  • 1
  • 13

2 Answers2

0

If you are going to put it in the Load event, consider making a template form. Somewhere in the template form, add your localisation checks. Then, have your other forms inherit the template, and they will get the Load event by default.

0

If you use the Language.resx, Language.[language]-[country].resx way of localizing, the generated class Language will have a property named Culture that can be set to override the current system culture.

Language.Culture = new CultureInfo("sv-SE");
label1.Text = Language.my_language_string;

If you want to use the ResourceManager-class it has a member GetResourceSet() that takes a parameter CultureInfo. I haven't tried to use GetResourceSet myself but it sounds like something you could use.

ResourceManager CultureResourceManager = new ResourceManager("My.Language.Assembly", System.Reflection.Assembly.GetExecutingAssembly());
ResourceSet resourceSet = CultureResourceManager.GetResourceSet("sv-SE", true, true);
resourceSet.GetString("my_language_resource");

MSDN-link: http://msdn.microsoft.com/en-us/library/system.resources.resourcemanager.getresourceset(v=vs.80).aspxo

Fredrik Ljung
  • 1,445
  • 13
  • 28