Example #1
0
        public CultureSelectorResult GetCulture(HttpContextBase context)
        {
            var cultureName = _browserCultureService.GetCulture(context);

            return(cultureName == null ? null : new CultureSelectorResult {
                Priority = _browserCultureService.GetSettings().Priority, CultureName = cultureName
            });
        }
Example #2
0
        public string GetCulture(HttpContextBase context = null, bool fallback2Browser = true)
        {
            if (context == null)
            {
                var workContext = _workContextAccessor.GetContext();
                if (workContext != null)
                {
                    context = workContext.HttpContext;
                }
            }
            if (context == null || context.Request == null || context.Request.UserLanguages == null)
            {
                return(null);
            }

            var settings = GetSettings();

            if (settings == null || !settings.Enabled)
            {
                return(null);
            }

            if (!context.Request.IsAuthenticated)
            {
                return(null);
            }
            var currentUser = _authenticationService.GetAuthenticatedUser();

            PreferedCulture pre = new PreferedCulture {
                User = currentUser, Culture = null, PreferredList = null
            };

            _profileHandlers.ProvidePreferredCultureRequest(pre);
            if (!string.IsNullOrEmpty(pre.Culture))
            {
                return(pre.Culture);
            }

            if (pre.PreferredList != null)
            {
                return(pre.PreferredList.OrderBy(t => t.Item2).Select(t => t.Item1).FirstOrDefault());
            }

            if (!fallback2Browser)
            {
                return(null);
            }
            // We should have a Profile Provider to bring back the user profile with its prefered culture
            // Defaults to browser
            return(_browserCultureService.GetCulture(context));
        }