为什么在更改设计器中的区域性时不会自动创建本地化资源文件?
我目前正在致力于本地化表单。然而,我对如何正确地做到这一点感到有些困惑。
我认为可以自动将控件属性导出到资源文件,但这似乎是一项手动任务。
我当前的方法是添加所有 String 类型且可写入资源文件的控件属性。这是通过递归枚举窗体上的所有控件和子控件并反映属性来实现的。
但这似乎有点复杂,我想知道其他人是如何做到的。
所以我的问题是: 使用资源文件进行控制文本本地化的最佳实践是什么?
编辑:我发现我做错了什么。我认为显示文本会自动复制到每个资源文件中。然而,似乎只有已更改的字段被复制。
所以基本上,我将语言设置为某个设置,更改所有控件的 DisplayText,当我将语言更改回(默认)时,更改将被保存。
感谢您的任何/所有评论。
I am currently working on localizing a Form. However I am somewhat confused as to how one correctly does this.
I thought it would be possible to export control properties to a resource file automatically, but it seems this is a manual task.
My current approach is to add all the Control Properties which are of type String and are writable to the resource file. This by recursively enumerating all the controls and child controls on the form and Reflecting the properties.
But this seems somewhat complicated, and I wonder how other people do this.
So my question:
What is the best-practice in terms of using a resource file for Control Text Localization?
Edit: I see what I am doing wrong. I thought the Displaytext would automatically be copied into each resource file. However it seems only the fields that have changed are copied.
So basically, I set the language to a certain setting, change the DisplayText for all the controls, and when I change the language back to (default), the changed are saved.
Thanks for any/all comments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯,实际上本地化表单并不难。您将“可本地化”属性设置为“true”。这会导致窗体上控件的所有可本地化属性都迁移到资源文件中。当前资源文件是与语言环境无关的文件。然后,您可以在表单属性中选择另一种语言,并将所有控件标题和文本替换为其翻译后的变体。这会导致创建并使用适当的与区域设置相关的资源文件。
您可以通过设置 Thread.CurrentThread 上的 CurrentCulture 和 CurrentUICulture 属性来选择界面显示的语言:
界面将相应地进行调整。
Well, actually localizing a form is not that hard. You set the "Localizable" property to "true". This causes all localizable properties of controls on the form to be migrated into a resource file. The current resource file is the locale-independent one. You can then select another language in the Form's properties and replace all control captions and texts with their translated variants. This causes the appropriate locale-dependent resource file to be created and used.
You can select the language in which the interface is displayed by setting the CurrentCulture and CurrentUICulture properties on Thread.CurrentThread:
The interface wil adapt accordingly.
它已经这样做了。
在表单或用户控件设计器中打开可本地化。
现在更改您的语言(也在设计器中),并且会自动创建适当的 langXXX.resx 。
It does this already.
Turn on Localizable in the Form or UserControl designer.
Now change you Language (also in designer), and the appropriate langXXX.resx is automagically created.
您只需要使表单可本地化(在属性面板中,将 Localizes 设置为 true)。然后您只需选择要本地化的语言即可。所有必需的资源文件都会自动生成
You just need to make the form localizable (in the properties panel, set Localizable to true). Then you just need to select the language for which you want to localizable. All necessary resource files are generated automatically