I follow the Globalization and localization and Building simple multilingual ASP.NET Core website tutorials to add a language switch for my application.
So, I create
Did you add javascript to make the language selector postback?
(function () {
$("#selectLanguage select").change(function () {
$(this).parent().submit();
});
}());
Did you wire up therequest localization middleware in Configure?
var locOptions= app.ApplicationServices.GetService>();
app.UseRequestLocalization(locOptions.Value);
Did you add a method in HomeController like this:
[HttpPost]
public IActionResult SetLanguage(string culture, string returnUrl)
{
Response.Cookies.Append(
CookieRequestCultureProvider.DefaultCookieName,
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)),
new CookieOptions { Expires = DateTimeOffset.UtcNow.AddYears(1) }
);
return LocalRedirect(returnUrl);
}