1

I need to make a legacy program (its huge) support another language. Despite how badly I'd love to send them my single language project files and ask them to do the rest of the work, the translation agencies tend to put up a fight when I do that.

SO I am looking to generate a list of all UI controls in a project and their default text that is currently displayed. I'll then send that out to the translator and I'll generate a .resx file with the results. As far as I understand, as long as I name the resx files correctly for the language i am targeting and the localizable able property is set to true, once the culture changes it will switch over all of the text on my controls. Let me know if i am off on this, I spend my time in the embedded world and for some reason the higher ups decided I should be the one to tackle this.

I figure i can parse through the designer file to get the list, but I was hoping someone has a more elegant solution or knows of one that someone has already built. This seems like it would be a pretty common task.

3
  • I have edited your title. Please see, "Should questions include “tags” in their titles?", where the consensus is "no, they should not". Commented May 14, 2014 at 18:57
  • I just copy+paste from the resx designer in VS into Excel and give the spreadsheet to the translator, then paste back when they're done. Commented May 14, 2014 at 18:59
  • @Dai- Whoever wrote this program hard coded alot into it, so for the english version there is no resx file. I am hoping when the culture changes to a new language and there is a property in, lets say, the Japenese resx file it will overwrite the hard coded english that is in there now. Commented May 14, 2014 at 19:05

2 Answers 2

1

Well, since I don't know some of the really important parameteres I can't be sure if e.g. going for a commercial tool is an option; also I don't know how many forms you have or how many forms and controls are created dynamically..

But for a simple control dumping function maybe something like this is a start:

private void dumpControls(Control ctl, string parents) { if (parents == "") parents = ctl.Name; else parents += "." + ctl.Name; if (ctl.Name != "" && ctl.Text != "") Console.WriteLine(parents + "=" + ctl.Text); foreach (Control ct in ctl.Controls) dumpControls(ct, parents); } 

You would put this into a form's constructor:

public Form1() { InitializeComponent(); if (dumpMode) dumpControls(this, ""); .. } 

If you don't want the full parent container list you can easily modify the code, for example like this:

 if (parents == "") parents = this.Name + "." + ctl.Name; else parents += "." + ctl.Name; if (ctl.Name != "" && ctl.Text != "") Console.WriteLine(parents + "=" + ctl.Text); foreach (Control ct in ctl.Controls) dumpControls(ct, "") 

You probably will want the form prepended to make the control refences unique across forms.

Obviously you would not only have to add this to each form, but also open each form. I don't know if that will be a problem, but I'm sure the real work will be going through your code and changing all hard coded literals that need translation to something else. I've been there and done that and used a dictionary; worked well but was quite a lot of work and also amazing, as I had no idea just how many literals has sneaked into my (own) code..

I load the strings on form load or when the user changes languages. In addition to the built-in resources; I can also read an external language file into the dictionary..

Instead of dumping the data to the Console you can stuff it into a StringBuilder and write that to a file, of course..

Sign up to request clarification or add additional context in comments.

1 Comment

@TaW- Thanks for the reply. You are right, finding the literals which are displayed in any one of the 80 or so windows has been quite a pain. I decided to parse out the controls from the default .resx files and dump the list to excel.
0

You can get the controls which is in your form using this code:

foreach (Control control in this.Controls) { MessageBox.Show(control.Name + "\n" + control.Text); } 

But it shows only controls which is on your form. If you have a groupbox, you should use same code your groupbox too. Or if you have tabcontrol, you should this do separately for it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.