Localizing a minimal API application
To enable localization within a minimal API application, let us go through the following steps:
- The first step to making an application localizable is to specify the supported cultures by setting the corresponding options, as follows:
var builder = WebApplication.CreateBuilder(args); //... var supportedCultures = new CultureInfo[] { new("en"), new("it"), new("fr") }; builder.Services.Configure<RequestLocalizationOptions>(options => { options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; options.DefaultRequestCulture = new RequestCulture(supportedCultures.First()); });
In our example, we want to support three cultures – English, Italian, and French – so, we create an array of CultureInfo
objects.
We’re defining neutral cultures, that is, cultures that have...