I'm planning to develop a localized Windows 8 Store App. Microsoft recommends using resource files in tagged directories and the ResourceLoader class, so –for now– that's what I'm planning to do.
For simple translations this works fine, e.g.:
var resourceLoader = new Windows.ApplicationModel.Resources.ResourceLoader();
string text = resourceLoader.GetString("FileDeletedMessage");
text = string.Format(text, fileName);
GetString
automatically matches the current culture and prefered language(s) with the most appropriate resource file and returns the corresponding entry, e.g. The file "{0}" was deleted
or Die Datei "{0}" wurde gelöscht
. This happens transparently.
But now I also want to implement proper pluralization as decribed in the CLDR charts of the Unicode Consortium. AFAIK, .NET does not support this out-of-the-box, right? Therefore I want to use or implement something like SmartFormat. In this scenario, GetString would return a string like {0} {0:file|files} {0:was|were} deleted
.
The problem: To apply the culture-specific pluralization rules to this string, I need to know the string's culture. But GetString does not provide it, only the string itself. Is there some way to look up the string and its culture? (I do not want to reimplement it myself. It's complex!)
BTW, using System.Globalization.CultureInfo.CurrentCulture
or CurrentUICulture
instead does not work, because GetString does not necessarily return a direct match for the current culture (Consider an application with a single localization, English, running on a French machine).