By SkySigal on
10/20/2008 6:11 PM
Over the years, I've found that breaking resources into several files saves time.
Multiple Resource Files
I use the following list as a starting point:
- Local Resources:
- Personally, I try my best to use Global resources as much as possible so that translations are not missed in the rush to release -- but invariably Global resources are not ready/finalized enough to rely on them by the time I need them.
- Navigation.resx
- Examples being: Go, Forward, Back, Next, Stop, Pause, etc.
- These types of strings are usually the same for most programs so once defined, and translated, end up being just a copy, paste job between existing applications and new ones.
- Although, in practice, this often ends up often merged together with:
- Menu.resx
- Examples being: &File,&Open, &Edit, &Cut, &Copy, &Tools, &Help
- Most of these strings are usually the same for most programs so once defined, and translated, and so start off being just a copy, paste job between existing applications and new ones.
- Messages.resx: for shared messages (and optionally error messages, in small programs).
- Examples being: "The file '{0}' has been downloaded.", "Total: {0:C}", etc.
- Mostly custom per program.
- ErrorMessages.resx: for shared error messages.
- Examples being: "Could not open the following file: '{0}'."
- Some error messages are quite common.
- Glossary.resx:
- Examples being: "Note", "Contact", "Email", etc.
- Definitely specific to an application.
- Configuration.resx
- FileNames, etc. not translated. Only used by developers.
- This can be argued that if not translated, why use a resource file for it (to keep a consistent approach, and modifiable prior to release).
Caching
Caching is a necessity -- but in a multicultural website, make sure you cache based on culture.
Four Cultures at Play:
Another point I would like to make is to use at least 3 cultures when programming -- and 4 Cultures would be even better:
- Set UICulture in order for the Framework to pull up the correct resources for visible UI strings and images.
- Set Culture in order for the Framework to correctly format dates, and numbers, as well as sort data.
- Use Culture for round tripping strings to visible text and back (ie new ListItem(data.ToString()),
or better still, Culture and CultureInfo.InvariantCulture to round trip data(ie: new ListItem(data.ToString(), data.ToString(CultureInfo.InvariantCulture)). - Use a custom _TransactionCulture for currencies -- it is is a culture neutral to both the client and server's culture.
Note:
The only one that can appear to be perplexing for a second is when trying to parse the value of eg: a TextBox that you've used to enter a Currency Value -- but note that you are actually not parsing a currency, but just a float, so its simpler: just parse it with the CurrentCulture, and then rendered ToString() using _TransactionCulture.
Note:
The reason for a slight preference towards using InvariantCulture for roundtripping data is that things can go wonky if the page was initially rendered using one Locale, and the region is changed on a Postback.
Note:
Not everyone will agree with me that Culture should be set to be the same as UICulture (see: http://msdn.microsoft.com/fr-fr/magazine/cc163609(en-us).aspx)
Note:
One way of to consider creating a TransactionCulture that has the commas/dots in the same format as the UICulture, but with the current currency symbol, would be to start with something like:
_TransactionCulture = CultureInfo.UICurrentCulture.Clone()
as CultureInfo;
_TransactionCulture.NumberFormat.CurrencySymbol = "€ ";
//and maybe more work to deal with number of
//decimal point, etc....
Did I miss something..?
Links:
Note:This is just a cut/paste from the much larger post that I did on globalization, in order to make it more readily accessible/linkable to from