pitaridis
pitaridis

Reputation: 2983

Set culture from a controller's action

I try to create a CMS for which I have to set the Culture Info depending on the language selection for a specific page. The only way to set the current language is the following:

System.Globalization.CultureInfo.CurrentCulture = new System.Globalization.CultureInfo("el-GR");
System.Globalization.CultureInfo.CurrentUICulture = new System.Globalization.CultureInfo("el-GR");

I tried to use these lines in the following locations:

The best solution to my problem would be to set the culture in the action (I have one action which handles all the CMS requests) but in case that this is not possible it would be helpful to find a way to set the culture in the _Layout.cshtml file.

Upvotes: 0

Views: 296

Answers (1)

Mohammad Olfatmiri
Mohammad Olfatmiri

Reputation: 1675

Please check this link Globalization and localization in ASP.NET Core.
there many ways to do that

Implement a strategy to select the language/culture for each request

  1. Localization middleware
  2. QueryStringRequestCultureProvider
  3. The Accept-Language HTTP header
  4. Use a custom provider

Upvotes: 2

Related Questions