I\'m designing a multilingual application using .resx files.
I have a few files like GlobalStrings.resx, GlobalStrings.es.resx, GlobalStrings.en.resx, etc. When I wa
A generic answer where the resource type to search is specified. Uses reflection but is cached.
Usage:
List comboBoxEntries = CommonUtil.CulturesOfResource()
.Select(cultureInfo => cultureInfo.NativeName)
.ToList();
Implementation (Utility Class):
static ConcurrentDictionary> __resourceCultures = new ConcurrentDictionary>();
///
/// Return the list of cultures that is supported by a Resource Assembly (usually collection of resx files).
///
static public List CulturesOfResource()
{
return __resourceCultures.GetOrAdd(typeof(T), (t) =>
{
ResourceManager manager = new ResourceManager(t);
return CultureInfo.GetCultures(CultureTypes.AllCultures)
.Where(c => !c.Equals(CultureInfo.InvariantCulture) &&
manager.GetResourceSet(c, true, false) != null)
.ToList();
});
}
It may suffer the same issue with the accepted answer in that all the language resources will probably be loaded.