Default Language hierarchy

Topics: Feature requests, General, Troubleshooting
Nov 8, 2012 at 1:55 PM



New to Orchard, I was used in another CMS, to have a language picker which was selecting the language according the following rules with decreasing priorities

1) the existing cookie if language is still ok in site

2) the first browser language corresponding to a language available in the site

3) the default site language

It seems that your code doesn't implement the second rule, is there a way to do it ?


Thanks for answer


Nov 8, 2012 at 5:25 PM


It's very easy to implement. Just need to create BrowserCultureSelector and set it's Priority between CookieCultureSelector and DefaultCultureSelector priorities.

Nov 8, 2012 at 7:43 PM

I will try but I am still trying to understand when and why the xxxSelectors get called ?

I will dig into the orchard code.


Nov 8, 2012 at 7:46 PM

You don't really need to care about how culture selectors get called. All you need to do is to implement BrowserCultureSelector : ICultureSelector and set correct priority to it. That's it.

Nov 8, 2012 at 8:56 PM
Edited Nov 8, 2012 at 8:57 PM

Could this do the job ?


    public class BrowserCultureSelector : ICultureSelector
        public const int SelectorPriority = -4; //priority is higher than SiteCultureSelector priority (-5) but lower than CookieCultureSelector (-3)

        #region ICultureSelector Members

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

            string browserCulture = (context.Request.UserLanguages.Length > 0) ? context.Request.UserLanguages[0] : null;

            return String.IsNullOrEmpty(browserCulture) ? null : new CultureSelectorResult { Priority = SelectorPriority, CultureName = browserCulture };

Nov 8, 2012 at 9:00 PM

Yes, it should do the trick.