全球化现有的 Windows 窗体应用程序?

发布于 2024-08-06 22:22:26 字数 376 浏览 1 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

她如夕阳 2024-08-13 22:22:26

我只接触过 LTR 语言,还没有接触过日语。考虑到这一点,以下是我的一些最佳实践:

  • 将所有特定于语言的编程字符串和字符串片段放入 .resx 文件中(我喜欢每个对话框使用一个 .resx 文件),然后调用使用自动生成的类和属性在字符串上。您的代码中不应保留任何特定于语言的字符串(这意味着您的代码中几乎没有任何字符串)。一个好的模式是将格式化字符串也放入 .resx 中,因为语言的语法各不相同。
  • 在所有表单上将 Localized 属性设置为 True,并直接在其中进行特定于语言的更改(使用 Language 属性)。
  • 设计您的表单,以便任何显示特定于语言的字符串的内容在需要时都具有额外的空间(注意:德语比英语长)。在我看来,表格不必因语言的基本变化而完全重新排列——不过,可能必须使用日语等语言来完成。
  • 对于需要动态设置文本的控件(例如标签),请在表单上设置文本,以便您知道它只是一个标记。我为此使用“##”,这确实很突出。避免将文本设置为动态文本的“样本”,因为您永远不会记住仅通过查看表单来动态设置哪些控件。

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:

  • Put all language-specific programmatic strings and string fragments into a .resx file (I like to use one .resx file per dialog box), then call on the strings using the auto-generated classes and properties. There shouldn't be any language-specific strings remaining in your code (which means almost no strings in your code, period). A good pattern is to put formatting strings into the .resx as well, since the syntax of a language varies.
  • Set the Localizable property to True on all your forms and make language-specific changes on there directly (use the Language property).
  • Design your forms so that anything that displays language-specific strings will have extra space where needed (note: German is longer than English). IMO, forms should not have to be completely rearranged for a basic change in language -- it may have to be done with a language like Japanese, though.
  • For controls such as labels that need their text dynamically set, set the text on the form so that you know it's only a marker. I use "##" for this, which really stands out. Avoid setting the text to a "sample" of the dynamic text, because you'll never remember which controls get set dynamically by just looking at the form.
慵挽 2024-08-13 22:22:26

最好在每个表单上设置本地化属性 - 这不仅会提取字符串,还会提取各种组件的几何图形到基本 .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.

分分钟 2024-08-13 22:22:26

如果您使用 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.

鸠魁 2024-08-13 22:22:26

如果您希望社区为您进行本地化,请使用外部 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文