Run my C# application in different language

2019-04-15 23:46发布

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

3条回答
爷、活的狠高调
2楼-- · 2019-04-16 00:13

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.

查看更多
Ridiculous、
3楼-- · 2019-04-16 00:16

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?

查看更多
叛逆
4楼-- · 2019-04-16 00:22

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

查看更多
登录 后发表回答