I have setup the cultures for my views and changing the culture in a controller but I can't seem to find how to know what culture I'm currently using in a controller, I'm looking for something like:
public class HomeController : Controller { public async Task<IActionResult> Index() { // Something like the next line var requestCulture = GetRequestedCulture() return View(); } }
This is much easier (CultureInfo.CurrentCulture.Name) since you can assign this to a global variable in constructor of controller and use it in whatever method you want inside the controller. While getting the culture through request will have you declaring the variable each time in each of the methods you want to use.
Copy the required culture JavaScript files from the \js\culture\ folder of your Telerik UI for ASP.NET Core installation to the wwwroot/lib/kendo-ui/js/cultures/ folder of your application. Get the current culture. Include the corresponding culture JavaScript file. Set the current culture by calling the kendo.
CurrentCulture = New CultureInfo("th-TH", False) Console. WriteLine("CurrentCulture is now {0}.", CultureInfo.CurrentCulture.Name) ' Display the name of the current UI culture. Console. WriteLine("CurrentUICulture is {0}.", CultureInfo.CurrentUICulture.Name) ' Change the current UI culture to ja-JP.
CurrentCulture is the . NET representation of the default user locale of the system. This controls default number and date formatting and the like. CurrentUICulture refers to the default user interface language, a setting introduced in Windows 2000.
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(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With