开发者

Automatic translation of text using CultureUI information

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 "开发者_如何学CControls". 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!


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.


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); }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜