I\'m going mad. I just want the culture used in the entire Asp.net core application to be set to \"en-US\". But nothing seems to work. Where to I set the culture for the ent
Localization is configured in the Startup.ConfigureServices method:
CultureInfo[] supportedCultures = new[]
{
new CultureInfo("ar"),
new CultureInfo("fa"),
new CultureInfo("en")
};
services.Configure(options =>
{
options.DefaultRequestCulture = new RequestCulture("ar");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
options.RequestCultureProviders = new List
{
new QueryStringRequestCultureProvider(),
new CookieRequestCultureProvider()
};
});
Startup.Configure method
app.UseRequestLocalization();
then UseRequestLocalization
initializes a RequestLocalizationOptions
object. This should be placed atleast before your UseMvc call
Change Culture:
[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);
}
Current language:
var currentLanguage = HttpContext.Features.Get().RequestCulture.Culture.Name;