Question

I recently watched the very useful orchard harvest video on localization and internationalization, by Piotr Szmyd

I want to set the culture using this method, checking for a cookie

public class CultureSelector : ICultureSelector
    {
        public const int SelectorPriority = 5;
        public const string CookieName = "Riders-Location-Cookie";
        public const string CookieValueName = "location-code";

        public CultureSelectorResult GetCulture(HttpContextBase context)
        {
            if (context == null || context.Request == null || context.Request.Cookies == null)
            {
                return null;
            }

            // check for a cookie 
            var cookie = context.Request.Cookies[CookieName];

            if (cookie != null && !string.IsNullOrEmpty(cookie.Values[CookieValueName]))
            {
                return new CultureSelectorResult { Priority = SelectorPriority, CultureName = cookie.Values[CookieValueName] };
            }

            return null;

        }
    }

That works, However, I do want to user to be able to reset their own culture on the site. How do I reset the culture for the entire site when the user chooses to.

Lets say for instance if I have a select list that is output as part of a custom module.

I've looked at the ChangeCulture code form the Orchard CulturePicker Module but this dosen't seem to change to culture for the entier site as setting it with an implementation of ICultureSelector would.

Was it helpful?

Solution

If I correctly understand, you'd like a user to be able to change his current culture and/or be able to return to the default site culture, right?

In your case it should be as easy as either changing the cookie value or removing it (to set default culture) as a response to some user action.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top