views:

710

answers:

3

So I've got a program that needs to be multilingual. The only difference between what I'm needing and what I've found on the web is that all the computers my program will run on are set to the localization of EN.

We have spanish speaking employees that will use the program just like the english speaking employees. So I won't be able to set something up based on the localization of the computer, it'll all have to be done in code.

I was thinking of trying to create an XML file (really just a dataset) for every form that I have and having each data table be a selectable language. In each table, it would have the information (control name, property, and text) to set the labels/checkboxes/etc that it needs to. I'll have to create a new form control so that I can have a generic function to go through and rename all of these controls if possible.

<DataSet>
   <English>
     <ControlName>labelHello</ControlName>
     <ControlProperty>Text</ControlProperty>
     <Text>Hello</Text>
   </English>
   <English>
     <ControlName>labelBye</ControlName>
     <ControlProperty>Text</ControlProperty>
     <Text>Bye</Text>
   </English>
   <Spanish>
     <ControlName>labelHello</ControlName>
     <ControlProperty>Text</ControlProperty>
     <Text>Hola</Text>
   </Spanish>
</DataSet>

Also I didn't know much about the strings in the resources file for each form. Could I do it from there and use .Net functions to achieve this?

So I'm up for lots of suggestions because I really don't want to go back into the program I just wrote and put this in, I hate going back and adding more functionality once I've already spent so much time with this sucker...

Thanks

+1  A: 

You can set the culture you want in code, e.g.:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-ES");

See this MSDN article for more info.

Joe
cool. So i take it that if you set this for the entire thread, everything will be this culture. I'd like to to be reset when it goes back to the "homepage". I guess I would have to set it back to EN myself if I used this method.thanks
Miles
Everything in the main thread will use the specified UICulture (and/or Culture) you set. Not sure what you mean by going back to the "homepage" - the title mentions WinForms and I understand "homepage" to be a web concept.
Joe
"homepage" is just the main form that I have on my program. It opens up children.So if I create background workers, since their on a different thread, will they have the same CurrentUICulture set?
Miles
Background workers won't inherit the culture automatically: you'll need to set it explicitly (though in some cases this won't be necessary, as the background worker often doesn't have any user interaction).
Joe
A: 

It is a pain, but its not hard. Within VS2008's WinForm designer, select the form, view its properties and set Localizable=True (if you view the partial class/code behind file you will see a new line that looks something like

  resources.ApplyResources(this, "$this")

Then, for each locale you want to support, select Language, and localize any changes needed over the Default local.

I believe Windows allows the user to specify a different locale for a specified application. I last tried this with Windows 2000.

GregUzelac
A: 

With Windows you can have a machine culture EN, but for the browser, individual users of the PC can select prefered cultures (IE & Firefox anyway). Everything else on PC is english In IE, go to tools, Options, click the language button on the general tab. You can specify a prefered hierarchy of languages.

Otherwise go with Joes answer.

Binary Worrier