全球化现有的 Windows 窗体应用程序?
我有一个使用 VS 2005 和 .net Framework 2.0 开发的现有 winforms 应用程序。
现在我们需要全球化这个应用程序。两个语言环境是德语和日语。
我知道我们可以使用表单的 localize 属性来创建本地化的表单资源,并且可以为消息框、异常等中使用的字符串提供其他资源文件。
我想知道全球化现有应用程序的最佳方法,我应该将 localize 属性设置为每种形式或者是否有一些工具可以提取标签名称和控件名称。日期格式、货币等需要考虑什么。
此外,我们在代码中的某些地方使用了一些复合字符串来连接消息字符串,如何本地化这些内容?
在开始全球化活动之前,我们将把应用程序迁移到 VS 2008 和 .net Framework 3.5。
I have an existing winforms application developed using VS 2005 and .net framework 2.0.
Now we need to globalize this application. The two locales are German and Japanese.
I know we can use form's localize property to create localized form resources and can have other resource files for strings used in message boxes, exceptions etc..
I want to know the best approach to globalize an existing application, should I set the localize property on each form or is there some tool which will extract the the label names and control names..what considerations to be taken for date formats, currency, etc.
Also we have used some composite strings in some places in code to concat the message strings, how these can be localized?
We will be migrating the application to VS 2008 and .net framework 3.5 before starting globalization activity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我只接触过 LTR 语言,还没有接触过日语。考虑到这一点,以下是我的一些最佳实践:
I've only worked with LTR languages, and I haven't touched Japanese. With that in mind, here are some of my best practices off the top of my head:
最好在每个表单上设置本地化属性 - 这不仅会提取字符串,还会提取各种组件的几何图形到基本 .resx 文件中。对于指定的语言,组件的原始大小不太可能适合翻译。
通常不建议用片段组成字符串,因为它们通常不会映射到不同语言的相同片段模式。是的,使用格式化字符串 (
String.Format
) 来插入值,但是任何依赖于原始语言的语法和句子顺序的内容都不太可能适合。It is better to set the localization property on each form -- that will extract not only the strings, but also the geometry of the various components, into the base .resx file. With the nominated languages, it is quite unlikely that the original sizes of the components will be a good fit for the translation.
It is generally not recommended to compose strings out of fragments because they in general will not map into the same pattern of fragments in a different language. Use of formatted strings (
String.Format
) to drop in values, yes, but anything that relies on the grammar and sentence order of the original language is unlikely to fit.如果您使用 Visual Source Safe 作为源代码管理(希望您没有这样做),无论您做什么,都不要在源代码本身中添加日语文本。虽然 Visual Studio 可以处理 unicode 源文件,但 VSS 不能很好地处理它们。
我开发了一个将自身翻译成日语的应用程序,并且在源代码本身中包含日语(用于调用类似 MessageBox 的函数)损坏了文件,并且由于 VSS 是基于 diff 的,因此文件一直被损坏返回到原始签入版本。这种损坏的形式是大多数代码文件都变成了基于日语字符的乱码,并且发生的原因是 VSS 将基于 unicode 的 CS 文件(每个字符使用两个字节)的部分移动了一个字节。
修复这些文件需要大量的手动工作,我的老板在我的肩膀上凝视着,尖叫着我们注定要失败,所以不要这样做。
另外,以下是有关此主题的其他几个 StackOverflow 问题:
在大型.NET项目中实现多语言/全球化的最佳方式
在 C#/WinForms 中制作多语言应用程序的最佳实践?
就个人而言,我更喜欢更简单的方法。在 Excel 或应用程序中需要翻译的每一段英文文本中创建一个列表(控制文本属性、在 MessageBox 函数中使用的字符串等),并将电子表格发送给您的翻译人员。在您的应用程序中,在每个表单的 Load 事件中调用一个方法,该方法循环访问表单上的所有控件,并将其 Text 属性更改为翻译后的值。将所有对 MessageBox 的调用替换为对翻译要显示的文本的中间函数的调用,然后使用翻译后的文本调用 MessageBox。
使用内置的全球化方法是一项繁重的工作,因为您必须手动创建每个全球化表单,然后手动用翻译替换所有文本,而这项任务几乎需要程序员流利。我提到的方法是以编程方式完成的,不需要程序员精通翻译的语言。
If you're using Visual Source Safe as your source control (hopefully you're not), whatever you do, do not add Japanese text inside your source code itself. Although Visual Studio can handle unicode source files, VSS does not handle them well.
I worked on an application that translated itself into Japanese, and the inclusion of Japanese within the source code itself (for calls to a MessageBox-like function) corrupted the files, and because VSS is diff-based, the files were corrupted all the way back to the original checked-in versions. This corruption took the form of most of the code files being turned into Japanese character-based gibberish, and occurred because VSS shifted portions of the unicode-based CS files (which used two bytes per character) off by one byte.
Fixing these files required a great deal of manual work, with my boss peering over my shoulder and screaming about how doomed we were, so just don't do this.
Also, here are a couple of other StackOverflow questions on this topic:
Best way to implement multi-language/globalization in large .NET project
Best practice to make a multi language application in C#/WinForms?
Personally, I prefer a simpler method. Create a list in Excel or something of every piece of English text in the application that you need to translate (control Text properties, strings to use in MessageBox functions etc.) and send the spreadsheets to your translators. In your application, call a method in the Load event of each of your forms that iterates through all the controls on the form and changes their Text properties to the translated values. Replace all calls to MessageBox with calls to an intermediate function that translates the text to be displayed, and then calls MessageBox with the translated text.
Using the built-in globalization methods is a lot of work, because you have to manually create each globalized form and then manually replace all the text with the translations, and this task pretty much requires the programmer to be fluent. The method I mention is done programatically, and doesn't require the programmer to be fluent in the translated languages.
如果您希望社区为您进行本地化,请使用外部 XML 文件。
看http://www.codeplex.com/url2jpeg,这个开源项目是这样本地化的并使用 Reflection 进行自动表单本地化。
对于字符串,只需使用隐藏标签。
If you want the community to localize for you use an external XML file.
Look at http://www.codeplex.com/url2jpeg, this open source project is localized this way and uses Reflection for automatic form localization.
For string simply use hidden label.