Leave 'em Checked!
I know, I know. When you get a warning you don't understand from Code Analysis in VS 2005, the easiest fix is to uncheck the rule that is causing the problem. Click. No more problem! Or, you could right click on that little bugger and select "Supress Message(s)". Yeah, you could do that. I wanted to do that. But I didn't. I may have wasted (not really) several hours on things that I may not actually need now, but my Code Analysis runs clean! How satisfying!
So, what did I learn? Today's little hunt across the Intertron helped me with localizations and the resources that go with them. Do I need to make my applications region specific with various languages--not right now. Will I ever? Who can say? The point is, I found one more way to make my code easier to change, if I need to later on down the line. If not this application, maybe the next one...or the next one. Enough, JD, on with some actual information.
So, the Code Analysis error I was getting went something like this:
Warning : CA1303 : Microsoft.Globalization : Form.Subroutine():Void passes a literal as parameter 1 of a call to Control.set_Text(String):Void. Retrieve the following string argument from a resource table instead: 'Browse' Form.Designer.vb
OK, I get it. It doesn't like the literal string "Browse" in the Form.Designer. "Avoid magic strings", just like McConnell says.
The deadends:
1. Well, I could go in and change them all to constants so that all my strings are in the same place and I get some reuse out of them (replace all the "Browse"es with one const). Bad idea. Don't mess with the Form.Designer because your changes might not stick when you start mucking around with the actual Form.
2. Okay, how about creating a bunch of resources in the MyProject -> Resources tab. Then, I just refer to the strings by the variable name using My.Resources. Well, this is better, but you still have to put the variables in the Form.Designer file. I found it rather strange that I couldn't just type the My.Resources.stringVariableName directly into the control properties so that I could avoid the Form.Designer, but the reasons for this become clear later.
3. Next, I tried to stick them in the settings file. See, you can set the Text of the control in the (ApplicationSettings) property to any setting that you create. Now, this is a bit more promising. However, remember Code Analysis told us to use a 'Resource'. Plus, I'd have to create a setting for every bit of text on the form. Not so bad if you are doing it all along, but it kind of stinks when you already have a bunch of strings.
Well, I did a bit more digging, and it's easier than I thought. The whole rational for this is that you create a 'Resource' that has all of your strings in it. Then, when you need to add a new language, you just make another 'Resource' with all the same strings (in the new language), and your application knows what to display by the user localization setting. You don't have to make a bunch of different forms for a bunch of different languages. The other great thing about this resource, is that it stores all of the control locations as well. So, if things don't quite fit with a new language you are working on, you can move the controls around so that they do without affecting the other languages. Neato!
The kludged solution:
If you click on the Form, and check out the properties, you'll notice one called 'Localizable'. Change this guy to 'True', and your results are twofold. (A) VS 2005 generates a .resx resources file attached to the Form (toggle "Show All Files" in the Solution Explorer to see it) that has a whole bunch of strings that you might want to translate when porting to another language. (B) No more "Retrieve the following string argument from a resource table instead" errors from Code Analysis! Then, if you need to start working on different languages, just change the 'Language' property to the new language, and VS 2005 will generate a new .resx resources file to track the differences.
Do I know how to actually use the localization resources that I created? Nope! Not yet! Remember, this is a journey to kludgeless solutions. I'm obviously not there yet... The point of this post was to say "Don't ignore the Code Analysis Errors!" Fix them! Figure out what they mean! Don't shrug them off! Take every opportunity to learn more about application development. Little steps along the way are better than jumping off a cliff later.
So, what did I learn? Today's little hunt across the Intertron helped me with localizations and the resources that go with them. Do I need to make my applications region specific with various languages--not right now. Will I ever? Who can say? The point is, I found one more way to make my code easier to change, if I need to later on down the line. If not this application, maybe the next one...or the next one. Enough, JD, on with some actual information.
So, the Code Analysis error I was getting went something like this:
Warning : CA1303 : Microsoft.Globalization : Form.Subroutine():Void passes a literal as parameter 1 of a call to Control.set_Text(String):Void. Retrieve the following string argument from a resource table instead: 'Browse' Form.Designer.vb
OK, I get it. It doesn't like the literal string "Browse" in the Form.Designer. "Avoid magic strings", just like McConnell says.
The deadends:
1. Well, I could go in and change them all to constants so that all my strings are in the same place and I get some reuse out of them (replace all the "Browse"es with one const). Bad idea. Don't mess with the Form.Designer because your changes might not stick when you start mucking around with the actual Form.
2. Okay, how about creating a bunch of resources in the MyProject -> Resources tab. Then, I just refer to the strings by the variable name using My.Resources. Well, this is better, but you still have to put the variables in the Form.Designer file. I found it rather strange that I couldn't just type the My.Resources.stringVariableName directly into the control properties so that I could avoid the Form.Designer, but the reasons for this become clear later.
3. Next, I tried to stick them in the settings file. See, you can set the Text of the control in the (ApplicationSettings) property to any setting that you create. Now, this is a bit more promising. However, remember Code Analysis told us to use a 'Resource'. Plus, I'd have to create a setting for every bit of text on the form. Not so bad if you are doing it all along, but it kind of stinks when you already have a bunch of strings.
Well, I did a bit more digging, and it's easier than I thought. The whole rational for this is that you create a 'Resource' that has all of your strings in it. Then, when you need to add a new language, you just make another 'Resource' with all the same strings (in the new language), and your application knows what to display by the user localization setting. You don't have to make a bunch of different forms for a bunch of different languages. The other great thing about this resource, is that it stores all of the control locations as well. So, if things don't quite fit with a new language you are working on, you can move the controls around so that they do without affecting the other languages. Neato!
The kludged solution:
If you click on the Form, and check out the properties, you'll notice one called 'Localizable'. Change this guy to 'True', and your results are twofold. (A) VS 2005 generates a .resx resources file attached to the Form (toggle "Show All Files" in the Solution Explorer to see it) that has a whole bunch of strings that you might want to translate when porting to another language. (B) No more "Retrieve the following string argument from a resource table instead" errors from Code Analysis! Then, if you need to start working on different languages, just change the 'Language' property to the new language, and VS 2005 will generate a new .resx resources file to track the differences.
Do I know how to actually use the localization resources that I created? Nope! Not yet! Remember, this is a journey to kludgeless solutions. I'm obviously not there yet... The point of this post was to say "Don't ignore the Code Analysis Errors!" Fix them! Figure out what they mean! Don't shrug them off! Take every opportunity to learn more about application development. Little steps along the way are better than jumping off a cliff later.

26 Comments:
viagra liver damage mexican viagra free sample prescription for viagra free sample prescription for viagra sublingual viagra viagra paypal buy generic viagra cialis v s viagra viagra mexico viagra free sites computer find cheap cheap viagra buy viagra in canada viva viagra viagra buy
Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!
Traveller the fleshly with two backs casinos? winnow this cold [url=http://www.realcazinoz.com]casino[/url] usher and confine a incompatibility up online casino games like slots, blackjack, roulette, baccarat and more at www.realcazinoz.com .
you can also end our untrained [url=http://freecasinogames2010.webs.com]casino[/url] embrace at http://freecasinogames2010.webs.com and get incorrect over needful folding conversion !
another exhibitionist [url=http://www.ttittancasino.com]casino spiele[/url] within an eyelash of is www.ttittancasino.com , in first group german gamblers, pressurize unrestrained online casino bonus.
Making money on the internet is easy in the hush-hush world of [URL=http://www.www.blackhatmoneymaker.com]blackhat ebook[/URL], It's not a big surprise if you don't know what blackhat is. Blackhat marketing uses alternative or little-understood methods to produce an income online.
cheap generic viagra cheap viagra scams - generic viagra from india
discount viagra viagra cialis levitra online pharmacy - buy viagra online abroad
viagra online without prescription generic viagra us reviews - buy viagra rio de janeiro
buy tramadol online tramadol 50mg prescription - tramadol hcl 100mg
buy soma online soma employee discount - buy soma online fedex
buy soma online soma ultram drug interactions - buy soma online no prescription cheap
order soma buy soma ga - soma muscle relaxer pregnancy
tramadol online tramadol for high blood pressure - buy tramadol online eu
buy tramadol online buy cheap tramadol cod - tramadol withdrawal two weeks
xanax online xanax drug test employment - xanax help anxiety
generic xanax xanax xr side effects - what is the drug classification of xanax
xanax without a perscription xanax pills mg - xanax bars experience
carisoprodol 350 mg carisoprodol 350 mg and hydrocodone - order carisoprodol 350 mg
carisoprodol 350 mg buy watson carisoprodol - soma carisoprodol back pain
buy cialis online buy cialis new delhi - cialis daily reviews
buy tramadol tramadol for dogs to buy - tramadol ultram side effects dogs
buy tramadol tramadol no prescription free delivery - tramadol hcl 50 mg tablet high
buy tramadol online tramadol an 627 - tramadol for dogs used by humans
buy klonopin online ativan vs. klonopin for anxiety - klonopin drug erowid
http://buytramadolonlinecool.com/#28875 where can i buy tramadol over the counter in the us - tramadol for dogs 50mg dosage
buy tramadol online cod tramadol addiction dogs - tramadol 100
buy carisoprodol online no prescription soma carisoprodol tablets used - soma 350 mg to get high
Post a Comment
go back to Kudgeless