0

This is my first try in globalization of windows forms, so I created form in my language and set property Localizable to true and left property Language on default, everything generated in default resource file, which was nice. After that I added new resource file called FormName.en.resx and renamed few stuff here just to test how it is working, but now everytime I run appliction It is using the English file that I added instead of default FormName.resx file, if I delete English resource file, everything goes back to normal, did I miss something?

First I thought that Windows is causing it but my languge is set correctly, I even tried changing Thread.CurrentThread.CurrentCulture manually but it always stays in English.

formatc
  • 4,261
  • 7
  • 43
  • 81

2 Answers2

0

The UI language which is used to determine the language of the resources is tied to the language pack of the OS by default. If you are running English Windows, then your application is going to pick up the English resources. If you want to force a different language, set the Thread.CurrentThread.CurrentUICulture property. The Thread.CurrentThread.CurrentCulture affects how Dates/Times/Numbers are formatted.

Eric MSFT
  • 3,246
  • 1
  • 18
  • 28
  • Well I tried nothing changed.. Is there some method that I need to call after I set CurrentUICulture? – formatc Jul 29 '12 at 14:48
  • You didn't state where you are making the call to set the UI culture. If you are trying to set it after UI has already been created, then you have to manually refresh the localized values. Typically setting the current thread's UI culture is done at startup before any UI is drawn in accord with a persisted setting. If you need to allow the user to set a preference for the UI culture within the application, you might want to consider restarting the application after persisting that setting. – Eric MSFT Aug 01 '12 at 17:15
0

Well this is a dirty way to do it I assume, but here it is if someone bumps into the same problem:

 private void ChangeLanguage(string lang)
        {       
            Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);

            //YourFormType should be the name of your form
            ComponentResourceManager resources = new ComponentResourceManager(typeof(YourFormType));
            resources.ApplyResources(this, "$this");

            foreach (Control control in this.Controls)
            {
                resources.ApplyResources(control , control.Name);
            }
        }

If someone has better solution please post it and I will try it

formatc
  • 4,261
  • 7
  • 43
  • 81