1

I have an application which I am trying to run and display in a language other than English which is the default language. I have assigned all text to use property files and have the relevant property files translated for each language.

However, when I run the application it is all English. I have set my keyboard, language, locale all to a foreign language and it should automatically pick this up and use the relevant property file automatically, however this is not happening.

I know there is not an awful lot of information there, but if you need any more i will provide. I am running the application from Visual studio 2010, so was wandering if this could affect it.

My files :

Strings.resx
Strings.en.resx
Strings.fr.resx

My usage:

Strings.HelloWorld
Nasreddine
  • 36,610
  • 17
  • 75
  • 94
pengibot
  • 1,492
  • 3
  • 15
  • 35

3 Answers3

4

You have to get the current culture from the OS and use it as such:

Basically what you need to do is set your current culture of your application somewhere:

Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CurrentCulture;

Related: How to set Silverlight CurrentUICulture/CurrentCulture correctly?

Community
  • 1
  • 1
Marcus
  • 8,230
  • 11
  • 61
  • 88
  • I thought the application should automatically do this depending on the language I was running under. I know this works as did it during testing. Didnt think I would have to set this myself in code. – pengibot Oct 04 '12 at 08:41
  • 1
    Actually, it should be set automatically but there are both CurrentCulture which derives its default value from regional settings in the OS and CurrentUICulture which derives its default value from the language setting in the OS. Try setting both explicitly like this: Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CurrentCulture; Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CurrentUICulture; – Marcus Oct 04 '12 at 08:49
  • my CurrentUICulture is en-US? which is probably why everything is still in English. Thanks for the heads up. Where can I change this in Windows to emulate the application running under a different language. – pengibot Oct 04 '12 at 09:15
  • Put this in the startup of your application: var culture = new CultureInfo("sv-SE"); Thread.CurrentThread.CurrentUICulture = culture; Thread.CurrentThread.CurrentCulture = culture; – Marcus Oct 04 '12 at 09:18
  • I installed the language pack needed using Windows Update. I wanted to properly emulate a foreign users pc set in the language. Thanks for all the help, it solved my issue. Marking this answer as the best. – pengibot Oct 04 '12 at 09:41
  • No worries! The sv-SE culture was just my example. It could be any culture. Good luck! – Marcus Oct 04 '12 at 10:03
2

If it's a WPF app, I recommend WPFLocalizeExtension. I use it all the time, works perfect.

Nickon
  • 9,652
  • 12
  • 64
  • 119
0

Thought I would add this here: http://www.west-wind.com/weblog/posts/2009/Jun/14/WPF-Bindings-and-CurrentCulture-Formatting

Basically you add this line of code to your App.xaml:

FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

It then overrides the default language property for every control in your application.

Thanks, Alex.

Alex Hope O'Connor
  • 9,354
  • 22
  • 69
  • 112