I'm working on a application (.NET, but not relevant) where there is large potential for resource/string duplication - most of these strings are simple like:
- Volume: 33
- Volume: 33 (dB)
- Volume
- 33 dB
- Volume (dB)
- Command - Volume: 33 (dB)
where X, Y and unit are the same.
Should I define a new resource for each of the string or is it preferable to use String.Format to simplify some of these, eg.:
String.Format("{0}: {1}", Resource.Volume, 33)
String.Format("{0}: {1} {2}", Resource.Volume, 33, Resource.dB)
Resource.Volume
String.Format("{0} ({1})", 33, Resource.dB)
String.Format("{0} ({1})", Resource.Volume, Resource.dB)
String.Format("Command - {0}: {1} {2}", Resource.Volume, 33, Resource.dB)
I would also define string formats like "{0}: {1}" in the resources so there would be a possibility of reordering words...
I would use this approach selectivly and not throughout the whole application..
And how about:
String.Format("{0}: {1}", Volume, Resource.Muted_Volume)
// = Volume: Muted
Resource.Muted_Volume
String.Format("{0}: {1} (by user {2})", Volume, Resource.Muted_Volume, "xy")
// = Volume: Muted (by user xy)
What about simple cases like "User" vs "User: " vs "User - "? Can you think of any culture where ':' would be in a different place or maybe a different character would be used?
The advantage is cutting the number of resource by the factor of 2-3 in my application.
Are there any hidden dangers of using this approach? Could someone give me an example (language/culture) where this would not work correctly?