适当的本地化的WinForms应用 [英] Proper localization of a WinForms application

查看:197
本文介绍了适当的本地化的WinForms应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我要翻译成多国语言WinForms应用程序。但是,我没有与本地化WinForms应用程序的经验,我觉得这个题目非常矛盾的信息。

I have a WinForms application which I want to translate into multiple languages. However, I do not have any experience with localizing a WinForms app, and I find very contradictory information about this subject.

基本上,我要的是:

  • 在源$ C ​​$ C,我想每种语言只有一个文件
  • 在该文件将被编译成汇编上的主要应用 - 构建应用程序后,没有卫星集或外部数据文件
  • 用户可以选择的语言,我不基于操作系统需要/想自动检测
  • 这应该主要包含字符串和整数,而且一个CultureInfo

我见过的无论是大多数解决方案都有每个表单和/或外部卫星组件之一时.resx文件。

Most solutions I've seen either have one .resx file per form and/or external satellite assemblies.

我必须推出自己的?或者是有什么在已有的框架?

Do I have to roll my own? Or is there something in the framework already?

.NET Framework 3.5 SP1中,如果该事项。

.net Framework 3.5 SP1 if that matters.

编辑:在大多数情况下,Visual Studio中已经提供的支持是我想要的,但有两个问题。当我设置Form.Localizable真我有这个漂亮的设计师的支持,但是这会产生每形成一个RESX。手动覆盖它的InitializeComponent的想法失败,因为它的设计师书面code,将定期被覆盖。从理论上讲,我只想一)覆盖创建ComponentResourceManager的把它指向我的全球RESX和b)改变调用ApplyResources到需要的CultureInfo作为第三个参数的重载。

For the most part, Visual Studio already offers support for what I want, but there are two issues. When I set Form.Localizable to true I have this nice designer support, but this generates one resx per form. The idea of manually overriding it in InitializeComponent fails because it's designer-written code that will regularly be overwritten. Theoretically, I only want to a) override the creation of the ComponentResourceManager to point it to my global resx and b) change the call to ApplyResources to the overload that takes a CultureInfo as third parameter.

看起来好像我有一个函数调用添加到我的构造thatgets的InitializeComponent(后称),并覆盖它的行为。这似乎是非常低效的,但Visual Studio是正确的,当它发出警告感人的InitializeComponent。目前,我确实是我自己的滚动的WinForms本地化框架...

It seems as if I have to add a function call to my constructor thatgets called after InitializeComponent() and overrides it's behaviour. That seems terribly inefficient, but Visual Studio is right when it warns about touching InitializeComponent. At the moment, I am indeed rolling my own WinForms localization Framework...

推荐答案

我刚刚完成了一个C#.net 3.5项目类似的问题。我们在写文章的WinForms插件为现有的多语言应用与8种语言(包括英语)。

I've just completed a C# .Net 3.5 project with a similar problem. We were writing WinForms plugin for an existing multi-lingual application with 8 languages (including English).

这是我们如何做到了:

  1. 创建我们所有的形式和用户界面的默认语言,英语。

  1. Create all our forms and UI in the default language, English.

将在资源文件中的所有我们的内部字符串(的东西不直接依赖于像自定义错误消息和对话框标题等形式)

Put all our internal strings in a resource file (stuff not tied directly to a form like custom error messages and dialog box titles etc)

在我们已经完成了大部分我们本地化它的工作和测试。

Once we had completed most of the work and testing we localised it.

  1. 每个表已经有了一个.resx文件,但这是空的。我们设置属性本地化为真,.resx文件中弥漫着像按钮的尺寸和放大器;字符串。

  1. Each form already had a .resx file but this was empty. We set the property 'Localizable' to true, the .resx file was filled with things like button sizes & strings.

对于每个其他语言,我们改变了形式的'语言'属性。我们选择每一种语言,例如基本版本:西班牙而不是西班牙语(智利)等。因此,这将工作的每一个'西班牙语'的话,我觉得

For each of the other languages, we changed the 'Language' property on the form. We chose the basic version of each language eg: 'Spanish' instead of 'Spanish (Chile)' etc. so that it would work for every 'Spanish' dialect, I think.

然后,我们通过各控制去了,它的翻译文本和调整大小,如果需要的话。这造成了每种语言与形式组合的.resx。

Then we went through each control, translated its text and resized, if needed. This created a .resx per language and form combination.

我们再留下,对8种语言,8的.resx为每个表单和8的.resx为普通字符串。当编译输出文件夹了,我们正在创建的.dll文件,然后一个子文件夹,在它.resources.dll每种语言。

We were then left with, for 8 languages, 8 .resx for each form and 8 .resx for the general strings. When compiled the output folder had the .dll we were creating and then a sub folder for each language with a .resources.dll in it.

我们能够通过只是改变了语言属性来检查,我们有正确的串和放大器,以测试在设计UI的版本;布局。

We were able to test the versions of the UI in the designer by just changing the language property to check that we had the correct strings & layout.

总之,一旦我们得到了我们的头周围,这是很容易的,无痛的。

All in all once we got our heads around it, it was quite easy and painless.

我们并不需要编写任何自定义调整的形式加载

We didn't need to write any custom tweaks to the form loading

这篇关于适当的本地化的WinForms应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆