Localizing my WinForms App
I’ve been trying to make this WinForms app that I have pass all the default FxCop rules. The last one that I’m stuck on is reading all my string literals from a resource file so that I can switch languages easily. This has turned out to be a pain in the ass.
It’s annoying to have to set every label’s text, every menu item drop down, etc. with a string from a resource file. I haven’t given it a whole lot of thought yet, but theres gotta be an easier way to do that.
Also, do I have to have a bunch of blank items on my form while I’m in design mode? If I blank out all the strings on my forms, won’t that still generate the following code in the designer.cs file?
label1.Text = “”;
Is FxCop smart enough to leave that alone, or will it still bark at me about a non-localized string?
I check it out and report back
Jim Losi said,
Wrote on July 26, 2006 @ 7:21 pm
can you abstract it out a bit more? like place the languages in an xml file and use a class to map the “words”? then bind your controls to what ever text was loaded into the “word” object?
I have never done localization before, though I have thought about it and how I would do it.
Just a thought …
Good luck
ben said,
Wrote on July 26, 2006 @ 9:15 pm
Jim, typically you place all the literal strings into a separate assembly for each language, then you load that satellite assembly based on the culture settings.
What I would like to see is some designer support for this. I wish that I could tell each control the name of the resource string to load at runtime and have it all happen automatically, detecting the culture, etc.
I am considering subclassing the typical controls to make them “culture aware” on their own, but we’ll see how it all shakes out
David M. Kean said,
Wrote on July 27, 2006 @ 10:05 am
Ben,
Simply set Localizable to true in the properties of the Form. This will causes the WIndows Forms Designer to automatically pull strings from resource files.
Regards
David
ben said,
Wrote on July 27, 2006 @ 10:12 am
David, thats ironic that you just left that comment. I read that somewhere and just finished up localizing the app right about the time you commented
The app now passes all the default FxCop rules too!
Ben Reichelt’s Weblog » Alright, so it was easier than I thought said,
Wrote on July 28, 2006 @ 9:19 am
[...] Ok, so it turns out to be very easy to localize a form in Visual Studio. As David mentioned in the comments on my previous post, all you need to do is set the Localizable property to true, and the VS designer will generate code to pull the strings from a resource file. [...]