how to get culture code of current request?

Muhammad Kaleem asked on May 28, 2019 14:04

i want to get culture code of current reuest for example a user opens a url www.abc.com/es-ES/news i want to get "es-ES" is there any class in kentico that can return culture code of current request, please suggest

thanks

Recent Answers


David te Kloese answered on May 28, 2019 14:17 (last edited on May 28, 2019 14:18)

As explained in the previous 4 questions you asked you have to make sure you use the correct culture!

CMS.Localization.LocalizationContext.CurrentCulture.CultureCode gives you the current culture. But just calling a url with a different culture doesn't automatically change the culture!

as shown in the example in the documentation: docs.kentico.com/.../setting-up-multilingual-mvc-projects

Take an extra look at the implementation of the MultiCultureMvcRouteHandler !

You'll see that the culture is set, based on the requested value of 'culture'.

        // Creates a CultureInfo object from the culture code
        var culture = new CultureInfo(cultureName);

        // Sets the current culture for the MVC application
        Thread.CurrentThread.CurrentUICulture = culture;
        Thread.CurrentThread.CurrentCulture = culture;
2 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.