I am developing an application using ASP.NET MVC 5. For the texts localization I am using a database instead of resource files.
In order to get the properly translated error messages for the various validation attributes (such as Required
, Range
, etc), I am using a custom metadata provider deriver from DataAnnotationsModelMetadataProvider
, as explained here. So far so good, everything works as expected.
The problem comes when I want to translate the default error messages such as "Field X must be a number". It seems that the ASP.NET MVC engine is not handling these errors through attributes so the cursom metadata provider is useless in the case.
In this page there is an explanation on how to translate these messages by using resource files, basically you add these lines in the Application_Start
method of Global.asax
:
ClientDataTypeModelValidatorProvider.ResourceClassKey = "MyResources";
DefaultModelBinder.ResourceClassKey = "MyResources";
...but I can't imagine how can I apply this when using a database for the texts.
So my question is: how to translate the ASP.NET MVC default (non validation attribute based) error messages when the texts are not in standard resource files?