在 C#/WinForms 中制作多语言应用程序的最佳实践? [英] Best practice to make a multi language application in C#/WinForms?

查看:18
本文介绍了在 C#/WinForms 中制作多语言应用程序的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究使应用程序适用于 C# 中的多种语言,因为我需要在一个小型项目上工作,在这种情况下.我发现基本上有两种方法可以做到这一点:

I've been looking into making applications suitable for multiple languages in C# since I need to work on a small project where this is the case. I have found basically two ways to do this:

将表单的 Localizable 属性设置为 true,设置 Language 属性,填充所有标签等,然后就大功告成了.我在这方面看到的主要缺点是:如何为多种语言准备不属于表单的其他内容(例如弹出窗口、日志文件或窗口等).

Set a form's Localizable property to true, set the Language property, fill all the labels and such, and you're 'done'. The major drawback I see in this is: how to make other stuff which is not part of a form ready for multiple languages (e.g. pop-up windows, log files or windows, etc).

创建一个资源文件,例如Lang.en-us.resx",为每种语言创建一个资源文件,例如Lang.nl-nl.resx"并用字符串填充它.IDE 似乎会自动为我生成一个类,因此在代码中我可以只使用 Lang.SomeText.我在这方面看到的最大缺点是:对于每个表单,我都需要自己在代码中设置所有标签和其他标题(而且似乎数据绑定不适用于这些资源).

Create a resource file, for example 'Lang.en-us.resx' and one for every language, for example 'Lang.nl-nl.resx' and fill it up with Strings. The IDE seems to generate a class for me automatically, so in the code I can just use Lang.SomeText. The biggest drawback I see in this is: for every form I need to set all the labels and other captions myself in the code (and it doesn't seem data binding works with these resources).

不过,我确信还有其他方法可以做到这一点.

I'm sure, however, that there are other methods to do this as well.

那么,最佳实践是什么?对于小型应用程序(一些表单、数据库连接等)来说,什么是最简单的?对于大型应用程序来说,什么是最适合扩展的?

So, what is the best practice? What's the easiest for small applications (a few forms, database connection etc) and what scales best for larger applications?

推荐答案

对于多语言应用程序,我一直使用资源文件.
网上有很多文章解释了如何使用它们.

我使用了两种不同的方式:

I have always used resource files for multi-language applications.
The are many articles on the web explaining how to use them.

I have used two different ways:

  • 每个表单一个资源文件
  • 一个全局资源文件

资源文件/表单,更容易实现,你只需要在资源文件中输入值,但我发现这种方法更难维护,因为标签分散在整个应用程序中.

The resource file / form, is easier to implement, you only need to enter the values in the resource file, but I find this approach harder to maintain, since the labels are dispersed throughout the application.

全局资源文件允许您将所有标签(图像等)集中在一个文件中(每种语言),但这意味着在表单加载中手动设置标签.此文件还可用于错误消息等.

The global resource file allows you to centralise all the labels (images etc.) in one file (per language), but it means manually setting the labels in the form load. This file can also be used for error messages etc.

口味问题...

最后一点,我用英语和法语编写程序,我使用en"和fr"而不是en-US"和fr-FR".不要把事情复杂化,英语的不同方言(美式、英语、澳大利亚等)几乎没有足够的差异,只能使用一种(法语也是如此).

One last point, I write programs in English and French, I use "en" and "fr" and not "en-US" and "fr-FR". Do not complicate things, the different dilelects of English (American, English, Australian etc) have few enough differences to use only one (the same goes for French).

这篇关于在 C#/WinForms 中制作多语言应用程序的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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