2

I have a MVC 5 project and need to set entire project to pt-BR culture/language. I want all messages (jQuery validation) like "The field X is required" to be translated to portuguese. (Other languages will not be supported)

Debugging the project in localhost, the message appears in portuguese, however after deploy to Azure, the messages appears in English (I tested opening the site in PC and Android mobile).

I have tried:

  • add the following line to "system.web" section in web.config:

    < globalization culture="pt-BR" uiCulture="pt-BR" />
    
  • install the Globalize NuGet package and run the following script:

    Globalize.Culture('pt-BR');
    
  • set default model binder to use custom resources:

    ClientDataTypeModelValidatorProvider.ResourceClassKey = "CustomResources";
    DefaultModelBinder.ResourceClassKey = "CustomResources";
    

    and in App_GlobalResources\CustomResources.pt-BR.resx add the following:

    Name                    Value
    PropertyValueRequired   Preenchimento obrigatório.
    

I read about using ErrorMessageResourceName and ErrorMessageResourceType in RequiredAttribute (DataAnnotations), but for this I need to change all properties in model with this parameters, however what I want is only change the default message "The field X is required" to all fields marked with the "[Required]" attribute.

Sparky
  • 98,165
  • 25
  • 199
  • 285
Oswaldo
  • 3,296
  • 4
  • 25
  • 35
  • Reading [this](http://stackoverflow.com/questions/6437150/requiredattribute-with-allowemptystring-true-in-asp-net-mvc-3-unobtrusive-valida) or [this](http://thatextramile.be/blog/2011/04/customizing-asp-net-mvcs-required-property-validation-messages/) may help you – Murali Murugesan May 28 '14 at 15:01
  • @Murali , I will try your tip using RequiredAttributeAdapter Class and give you feedback later. Thanks very much for your time! – Oswaldo May 28 '14 at 18:53
  • @MuraliMurugesan Second Link is broken – maracuja-juice Oct 04 '16 at 10:23

0 Answers0