制作多语言用户控件
我正在开发一个用户控件,现在(在工作结束时)我面临着使其成为多语言的问题。 我想我可以这样继续:
- 对于 UI 部分,我可以在控件上设置
Localizes = true
并让 VS 生成默认语言所需的所有“记录”。 - 然后我必须手动添加用于动态菜单、消息等的所有字符串
- 最后我需要为我需要的语言创建所有资源文件
因此使用 MSDN
Assembly myAssembly = this.GetType().Assembly;
ResourceManager mgr = new ResourceManager("namespace.resource", myAssembly);
mgr.GetString(...)
我的工作可以(轻松)完成。
但我有一些问题:
- 当最终用户使用我的控件(生成的 DLL)时,由于目标应用程序中的主命名空间发生更改,我在使用 new ResourceManager(...) 时是否会遇到一些问题?
考虑一下我不知道最终用户将使用哪个命名空间。 - 当我创建语言资源时,VS 生成附属程序集:有没有办法可以将这些文件“集成”到我的目标 DLL 中?
如果可能的话,我只想部署一个文件... - 有更好的方法来完成我的任务吗?
- 当我开发多语言控件时,我真的需要关心什么吗?
感谢大家
更新:(感谢@lak-b的一些建议)
我经过一番研究回答了一些问题:
- 是的,我可以对命名空间进行硬编码,并且不会改变 em> 当最终用户将我的控件放在他的表单上时
- 好吧,似乎没有一个简单的方法。
无论如何这篇文章提供了精彩的课程和出色的解决方案! - ...不,对于这个问题我仍在等待有人告诉我更好/更简单的方法
- lak-b 指定了一些关键点。
还有什么我需要担心的吗?
再次感谢
I'm developing a user control and now (quite at the end of the work) I'm facing the problem of making it multi-language.
I think I could proceed in this way:
- For UI part I could set
Localizable = true
on control and let VS generates all "records" I need for default language. - Then I have to manually add all the strings I use for dynamic menus, messages and so on
- Finally I need to create all resources file for languages I need
So using code from MSDN
Assembly myAssembly = this.GetType().Assembly;
ResourceManager mgr = new ResourceManager("namespace.resource", myAssembly);
mgr.GetString(...)
my job could (easily) be done.
But I have some question:
- When my control (generated DLL) is used from an end-user, can I have some trouble using
new ResourceManager(...)
because of main namespace changes in target app?
Consider I don't know which namespace end-user is going to use. - When I create languages resources, VS generates satellite assemblies: is there a way I can "integrate" these files inside my target DLL?
I'd like to deploy just one file if possible... - Is there a better way to accomplish my task?
- Is there something I really have to care when I develop a multilaguage control?
Thanks to everybody
UPDATE: (thanks to @lak-b for some suggestion)
I answer some question after some research:
- It's true, I can hardcode namespace and that won't be changed when end-user puts my control on his form
- Well, it seems there's not an easy way.
Anyway this SO post provides a wonderful lesson and a great solution!! - ... no, for this question I'm still waiting for someone to tell me a better/easier way
- Some critical point was specified from lak-b.
Is there something else I have to be worried about?
Thanks again
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看 制作多语言的最佳实践C#/WinForms 中的应用程序?
等等。
Take a look Best practice to make a multi language application in C#/WinForms?
and so on.