C# - Windows CE的:翻译形式独立于操作系统的区域性设置 [英] C# - Windows CE: form translation independent of OS culture settings
问题描述
我写在C#中为Windows CE设备的程序,并希望应用程序根据应用程序本身的语言环境进行翻译。
I am writing a program in C# for a Windows CE device and would like the application to be translated according to a language setting in the application itself.
我有已经阅读使用资源文件和翻译使用'本地化'和'语言'性质的形式本地化的一些文章。从我读书,我明白,这类型的表单翻译的工作原理与操作系统的语言设置(纠正我,如果我错了)。
I have already read some articles about localisation using resource files and translating forms using the 'Localizable' and 'Language' properties. From what I have read I understand that this type of form translation works with the OS language setting (correct me if I am wrong).
现在我正在寻找一种方式做形式翻译依赖于我自己的程序语言设置,最好使用资源文件。
Now I am looking for a way to do the form translation dependent on my own in-program language setting, preferably using resource files.
我已经想到在每个窗体的Load事件做这个翻译但也许还有其他的解决方案或最佳实践这一点。 。任何帮助表示赞赏。
I have already thought of doing this translation in the Load event of each form but maybe there are other solutions or best-practice for this. Any help is appreciated.
推荐答案
如果您使用Language.resx,语言[语言] - [国家]的.resx方式本地化的,生成的类语言将可以设置覆盖当前系统区域性名为文化属性。
If you use the Language.resx, Language.[language]-[country].resx way of localizing, the generated class Language will have a property named Culture that can be set to override the current system culture.
Language.Culture = new CultureInfo("sv-SE");
label1.Text = Language.my_language_string;
如果你想使用带有一个参数的CultureInfo ResourceManager的类它有一个成员GetResourceSet() 。我还没有尝试过使用GetResourceSet自己,但它听起来就像是你可以使用。
If you want to use the ResourceManager-class it has a member GetResourceSet() that takes a parameter CultureInfo. I haven't tried to use GetResourceSet myself but it sounds like something you could use.
ResourceManager CultureResourceManager = new ResourceManager("My.Language.Assembly", System.Reflection.Assembly.GetExecutingAssembly());
ResourceSet resourceSet = CultureResourceManager.GetResourceSet("sv-SE", true, true);
resourceSet.GetString("my_language_resource");
这篇关于C# - Windows CE的:翻译形式独立于操作系统的区域性设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!