You can't localize enum names (those retreived from Enum.ToString()) and you can't localize Attribute values.
The only thing you can do is use a enum value to lookup text in the resources so the resource manager can load the appropriate text for the CurrentUICulture. You could use the enum name as the Name in your resources. For example, if you had the following enum:
enum Ordinal
{
Unknown = 0,
First = 1,
Second = 2,
}
And the following entries in your resources:
<data name="First" xml:space="preserve">
<value>1st</value>
</data>
<data name="Second" xml:space="preserve">
<value>2nd</value>
</data>
<data name="Third" xml:space="preserve">
<value>3rd</value>
</data>
You could get "1st" using:
String text = global::MyNamespace.Properties.Resources.ResourceManager.GetString(Ordinal.First.ToString());
Or:
String text = global::MyNamespace.Properties.Resources.ResourceManager.GetString("First");
Or, if you didn't want to couple the enum value name to something in the resources you could use a switch:
Ordinal ordinal = Ordinal.First;
switch (ordinal)
{
case Ordinal.First:
text = global::MyNamespace.Properties.Resources.ResourceManager.GetString("SomeName");
break;
case Ordinal.Second:
text = global::MyNamespace.Properties.Resources.ResourceManager.GetString("SomeOtherName");
break;
default:
text = global::MyNamespace.Properties.Resources.ResourceManager.GetString("UnknownMessage");
break;
}
|