I've implemented RequestLocalization
for es-ES
with a single MVC view via the following (note: this code is condensed to only the most relevant pieces):
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix,
opts =>
{
opts.ResourcesPath = "Resources";
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
var english = "en-US";
var englishRequestCulture = new RequestCulture(culture: english, uiCulture: english);
var supportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US"),
new CultureInfo("es-ES")
};
var options = new RequestLocalizationOptions
{
DefaultRequestCulture = englishRequestCulture,
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
};
app.UseRequestLocalization(options);
app.UseMvc();
}
When passing culture=en-US
or culture=es-ES
as query string parameters, this works perfectly. My expectation is that the default culture should be en-US
when no culture is provided. However, when I do not provide the culture parameter, my view is defaulting to es-ES
. I have confirmed that all other Localization providers are also defaulted to en-US
.
I should also note that I attempted Localization via ConfigureServices()
but was unable to get this to function at all:
services.Configure<RequestLocalizationOptions>(
options =>
{
var supportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US"),
new CultureInfo("es-ES")
};
options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});