Run my C# application in different language

2019-04-15 23:26发布

问题:

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

回答1:

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

  • WPF: http://msdn.microsoft.com/en-us/library/vstudio/ms788718(v=vs.100).aspx

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?



回答2:

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



回答3:

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.