How to make an ASP.NET Core MVC application for Portuguese?

0

I would like to be able to make an application in Portuguese. I already did this with ASP.NET MVC 5 in a very simple way through a NuGet installation.

But I did not find anything similar for the CORE version. I already used the configuration:

        var supportedCultures = new[] {
            new CultureInfo("pt-BR")
        };

        app.UseRequestLocalization(new RequestLocalizationOptions {
            DefaultRequestCulture = new RequestCulture("pt-BR"),
            // Formatting numbers, dates, etc.
            SupportedCultures = supportedCultures,
            // UI strings that we have localized.
            SupportedUICultures = supportedCultures
        });

to handle requests in Portuguese, but auto-error messages are still in English:

  

The description field is required.

How can I configure my application for Portuguese?

    
asked by anonymous 04.06.2017 / 18:20

1 answer

3

To locate the error messages you need to add another service: AddDataAnnotationsLocalization.

Example:

public void ConfigureServices(IServiceCollection services)
{
    services.AddLocalization(options => options.ResourcesPath = "Resources");

    services.AddMvc()
    .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
    .AddDataAnnotationsLocalization();
}

In the case above, a Resource is used following the \ Resources \ Path \ Do \ Model.resx

Model

[Display(Name = "Name")]
[Required(ErrorMessage = "Required")]
public string Name { get; set; }

Resource

Name: Name
Value: Nome

Name: Required
Value: O campo {0} é obrigatório.
    
30.08.2017 / 07:32