1
votes

Where is the best location to place resource strings? Does it depend on scope? Currently most of our strings are being placed at the project level, but certain strings are only needed for one form. My thoughts would be that these strings should be placed as close to their use as possible.

2
I'm not sure I understand what you mean. Wouldn't a "resource" string by definition be placed in the project resources?C. Ross
In WinForms there are also resource files available at the WinForm level. While I've never used resources at this level, I was curious about whether or not other people had and what their approach has been.Blake Blackwell

2 Answers

4
votes

You should strongly favor using resources at the form level (set the form's Localizable property to True in the designer). The designer has very good support for it and the WinRes.exe utility is available to localize strings off-line. No code is required.

Localizing project resource strings is possible but not well supported by the IDE. Check my answer in this thread for an approach.

3
votes

Here's what I do (not necessarily the best way, but it's worked well so far) for adding programmatic strings, in addition to using language-sensitive strings directly on forms:

Aside from adding a ridiculous number of folders into the project to group by form, I haven't been able to find a clean solution other than keeping the .resx files in their own Resources folder. Usually I'll have something like:

Resources\Language
Resources\Xml
Resources\Images
etc.

I've found that using one .resx file per form is the best way to go, because you never know when you're going to need to add another string. I also create a Common.resx for strings such as "Save", "Load", etc., that are applicable to the whole application and will be used in multiple spots. With the one-.resx-per-form model, you have to be strict about only using strings in that form, which will probably mean repeating a few strings along the way as your application grows. But this is far easier to maintain than having a spiderweb of references between forms and .resx files.

For custom controls, I put the .resx files with the source files, since they usually have their own folder, and the strings won't be used outside that custom control anyway. (Note: this also means the custom controls should NOT use strings outside its own .resx file.) This will also allow you to easily extract a whole custom control into a separate assembly if necessary.

For user controls, usually they're application-specific, so it's not so bad tying the common language stuff to it, but certainly I'll use a separate .resx for strings specific to the user control, and follow the same folder structure as with the custom controls.