使用 CultureUI 信息自动翻译文本
我有一个窗口,其中有许多控件,这些控件组织在容器中,并且想要翻译 UI(即“文本”属性)。
最好的方法是什么?
我尝试迭代表单中的所有控件,但遇到了麻烦,因为每个容器提供了不同的方式来访问其子级。
还有更复杂的方法吗?我已经在不同的文化中使用 ResourceManager,所以如果我可以将它用于我的目标,那就太好了。
编辑: 我的问题是,我无法使用递归,因为 MenuStrip 控件可以使用“Items”属性而不是“Controls”来访问其项目。 StatusStrip 控件类似。
我已在 https://codereview.stackexchange.com/questions/721/automatic- 中发布了我的解决方案Translation-of-forms - 我很想听听您的评论!
I have a windows with many controls in it, which are organized in containers, and would like to translate the UI (i.e the "text" property).
What is the best way to do it?
I tried to iterate over all the controls in the form, but came into troubles, since each container provides different way to access its children.
Is there more sophisticated way? I'm already using the ResourceManager with different Cultures, so it would be great if I can use it for my goal.
EDIT:
My problem is that I can't use recursion because of the MenuStrip control, for instance, which gives access to its items using the "Items" property rather than "Controls". The StatusStrip control is similar.
I have posted my solution in https://codereview.stackexchange.com/questions/721/automatic-translation-of-forms - I'd love to hear your reviews!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要做的只是 2 个步骤:
1 - 将表单的可本地化属性设置为 true。
2 - 将表单的语言设置为所需的语言并编辑文本属性。 - 默认情况下,语言设置为(默认)。您需要将语言设置为某种特定语言,例如西班牙语、日语等。设置语言时,您还需要进行一些更改才能生成所需语言的 .resx 文件。完成此操作后,您需要将表单的语言设置为另一种所需的语言并修改控件的文本属性。
执行上述步骤后,您会注意到每种语言都有一个资源文件,在更改操作系统的 UI 文化/区域设置时会自动加载该资源文件。
All you require to do is 2 Steps:
1 - Set the Localizable Property of the form to true.
2 - Set a Language of the Form to the desired language and edit the text property. - By default the Language is set to (Default). You are required to set the language to some specific language such as Spanish, Japanese etc. On setting the language, you are also required to make some change to get the .resx file for the desired language generated. Once you are done with this, you need to set the language of the form to another desired language and modify the text property of controls.
After performing the above stated steps, you will notice that you have a one resource file per language which will automatically be loaded when changing the UI Culture/locale of the OS.
要迭代表单中的所有控件,您需要递归。假设您在某种形式的方法中放置了“Walk(this)”,那么下面的代码将检查每个控件。
static void Walk(控制控制)
{
foreach(control.Control 中的 var c)
步行(c);
}
To iterate over all controls in a form, you need recursion. Assuming you place a "Walk(this)" in some form method, then the code below will check each control.
static void Walk(Control control)
{
foreach (var c in control.Control)
Walk(c);
}