La solución más limpia que he encontrado hasta ahora es: http://www.codeproject.com/Tips/514321/A-Simple-and-Effective-Way-to-Localize-ASP-Net-MVC.
Comentarios/Comentarios son bienvenidos.
Editar 1: Según los comentarios, agregué ejemplos de código y usé el enlace como referencia.
creé una clase customDataAnnotationsProvider:
public class CustomDataAnnotationsProvider: DataAnnotationsModelMetadataProvider
{
private ResourceManager resourceManager = new ResourceManager();
protected override ModelMetadata CreateMetadata(
IEnumerable<Attribute> attributes,
Type containerType,
Func<object> modelAccessor,
Type modelType,
string propertyName)
{
string key = string.Empty;
string localizedValue = string.Empty;
foreach (var attr in attributes)
{
if (attr != null)
{
if (attr is DisplayAttribute)
{
key = ((DisplayAttribute)attr).Name;
if (!string.IsNullOrEmpty(key))
{
localizedValue = resourceManager.GetLocalizedText(key);
((DisplayAttribute)attr).Name = localizedValue;
}
}
else if (attr is ValidationAttribute)
{
key = ((ValidationAttribute)attr).ErrorMessage;
if (!string.IsNullOrEmpty(key))
{
localizedValue = resourceManager.GetLocalizedText(key);
((ValidationAttribute)attr).ErrorMessage = localizedValue;
}
}
}
}
return base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
}
}
Entonces hice referencia al proveedor personalizado en ApplicationStart en Global.asax
ModelMetadataProviders.Current = new Project.Web.Helpers.CustomDataAnnotationsProvider();
Usted no tiene que cambiar su modelo y puede utilizar la anotación de visualización :
[Display(Name = "CustomerAccountNumber")]
public string CustomerAccountNumber { get; set; }
posible duplicado de [ASP.NET MVC 2 Localization/Globalizatio n almacenado en la base de datos?] (http://stackoverflow.com/questions/2568129/asp-net-mvc-2-localization-globalization-stored-in-the-database) – jrummell