Get the current culture in a controller asp.net-core
The answer was on the Request Object, here's the code:
public async Task<IActionResult> Index() {
// Retrieves the requested culture
var rqf = Request.HttpContext.Features.Get<IRequestCultureFeature>();
// Culture contains the information of the requested culture
var culture = rqf.RequestCulture.Culture;
return View();
}
JohnnysAce answer works. If you just want an easy way to get the current culture, it is done as always in .net:
CultureInfo uiCultureInfo = Thread.CurrentThread.CurrentUICulture;
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
If you want to use IRequestCultureFeature (see JohnnyAces answer; because of dependency injection and better testability), you have to configure things in Startup.cs. Microsoft provided a sample here https://github.com/aspnet/Entropy/blob/2fcbabef58c2c21845848c35e9d5e5f89b19adc5/samples/Localization.StarterWeb/Startup.cs