Note that there are some explanatory texts on larger screens.

plurals
  1. POAvoiding resource (localizable string) duplication with String.Format
    primarykey
    data
    text
    <p>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:</p> <ul> <li>Volume: 33</li> <li>Volume: 33 (dB)</li> <li>Volume</li> <li>33 dB</li> <li>Volume (dB)</li> <li>Command - Volume: 33 (dB) </li> </ul> <p>where X, Y and unit are the same.</p> <p>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.:</p> <pre><code>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) </code></pre> <p>I would also define string formats like "{0}: {1}" in the resources so there would be a possibility of reordering words...</p> <p>I would use this approach selectivly and not throughout the whole application..</p> <p>And how about:</p> <pre><code> 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) </code></pre> <p>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?</p> <p>The advantage is cutting the number of resource by the factor of 2-3 in my application.</p> <p>Are there any hidden dangers of using this approach? Could someone give me an example (language/culture) where this would not work correctly?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload