Run my C# application in different language

强颜欢笑 提交于 2019-12-22 00:27:15

问题


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.



来源:https://stackoverflow.com/questions/12723021/run-my-c-sharp-application-in-different-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!