How do you localize enums for a ListBoxFor where multiple options are possible?
For example an enum that contains roles:
pu
I use this currently, hope it helps!:
///
/// Retrieves a translated value from an enumerated list.
///
/// Enum
/// string
/// string
protected string GetTranslatedEnum(Enum value, string resource)
{
string path = String.Format("Resources.{0}", resource);
ResourceManager resources = new ResourceManager(path, global::System.Reflection.Assembly.Load("App_GlobalResources"));
if (resources != null) {
return resources.GetString(value.ToString());
} else {
return value.ToString();
}
}
Created a .resx file named "App_GlobalResources\ProductNames.resx".
Usage:
// Convert the ProductId integer on the item to its Enum equivalent.
Products product = (Products) item.ProductId;
string productName = this.GetTranslatedEnum(product, "ProductNames");