Why aren't the localized resource files created automatically when changing the culture in the designer?

旧城冷巷雨未停 提交于 2019-12-09 07:16:08

问题


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.


回答1:


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:

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-GB");

The interface wil adapt accordingly.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/1459100/why-arent-the-localized-resource-files-created-automatically-when-changing-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!