1

Does Microsoft implementation of C# runtime offer some localization mechanism to translate common strings like Overflow, Stack overflow, Underflow, etc...

See the code below - it's a part of Mono and Mono itself has a Locale.GetText routine for making such translations.

// Added to avoid possible integer overflow.
if (inputOffset > inputBuffer.Length - inputCount)
    throw new ArgumentException("inputOffset" +
                                Locale.GetText("Overflow");

Now - how is it done in Microsoft version of runtime and how can I use it, for example, to get the localized equivalent of Overflow without adding resource files?

Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148

3 Answers3

4

.NET provides a framework that makes it easy to localize your content (ResourceManager) and while it internally maintains some translations for its own purpose (for example DateTime.ToString gives you a textual representation for the date/time that is locally appropriate, which includes the translated month and day names), it does not provide you with any ready-made translations, be they common strings or not. It could hardly do this reliably anyway, as there is a plethora of human languages out there and words can have different translations depending on context etc.

In your example, I would say that you are OK with untranslated exception messages. Although Microsoft recommends that you localize exception descriptions and they do localize their own (at least for major languages), this advice seems ill-thought at it's not only a waste of effort to translate all this text that users probably should never see, but it can make debugging a nightmare.

Community
  • 1
  • 1
Clafou
  • 15,250
  • 7
  • 58
  • 89
1

Yes, it does and it's a terrible idea. It makes debugging so much harder.

skolima
  • 31,963
  • 27
  • 115
  • 151
1

without adding resource files

What do you have against resource files? Resources are the prescribed way to provide localized and localizable strings, images, and other data for a .NET app or assembly.

Note that single word substitution as shown in your example code will result in poor quality translations. Different languages have different sentence structure and word order which your single word substitution won't accommodate. Non-English languages often involve genders for nouns and declension of words to properly reflect their role and number in a phrase. Single word substitution fails miserably at this.

Your non-English customers will most likely prefer that you not butcher their language by attempting to partially translate text a word here and a word there. If you're going to go to the trouble of supporting localizable messages, do it right and allow the entire string to be translated so that word ordering and declension can be done properly by translators. In cases where the content is variable, make the format string a resource so that the translator can set off the variable data using the conventions of the language.

dthorpe
  • 35,318
  • 5
  • 75
  • 119