I am able to localize model classes properties in a following way:
public class Person
{
[Display(Name = ResourceKeys.Person_FirstName)]
[Required(Name = ResourceKeys.Person_FirstName_Required)]
public string FirstName { get; set; }
//...other properties
}
Where "ResourceKeys" is special class, that stores the "pseoudo" keys and links them with the "proper" keys in relevant resource file:
public class ResourceKeys
{
public const string Person_FirstName = "FirstName"; // looks up for key "FirstName" in Person."culture".resx file
public const string Person_FirstName_Required = "FirstName_Required"; //dtto
//...
}
This works well - for example @Html.DisplayNameFor(model => model.FirstName) is localized correctly and rendered as 'Vorname' for german language.
Now to the problem. When new class is derived, the derived properties are not localized:
public class Student : Person
{
//...
}
For example @Html.DisplayNameFor(model => model.FirstName) is probably not localized at all and rendered as 'FirstName'. It seems like only the student resource file is searched for the key and as it is not found the key itself is rendered.
I definitely want to avoid duplicates in resource files of base and derived classes. How can I achieve this?
Edit: Localization of derived properties does not work even if the ResourceKeys class is omitted and annotation strings are directly "hardcoded":
public class Person
{
[Display(Name = "FirstName")]
[Required(Name = "FirstName_Required")]
public string FirstName { get; set; }
//...other properties
}