Esempio n. 1
0
        protected override DriverResult Display(CulturePickerPart part, string displayType, dynamic shapeHelper) {
            var siteAvailableCultures = _cultureManager.ListCultures().AsQueryable();
            var context = _workContextAccessor.GetContext();
            var baseUrl = context.CurrentSite.BaseUrl;
            var cleanUrl = context.HttpContext.Request.Url.AbsoluteUri.Replace(baseUrl, "");
            cleanUrl = context.HttpContext.Server.UrlDecode(cleanUrl);
            cleanUrl = cleanUrl.StartsWith("/") ? cleanUrl.Substring(1) : cleanUrl;
            // reading settings
            var settings = _extendedCultureService.ReadSettings();
            part.AvailableCultures = settings.ExtendedCulturesList;
            part.ShowOnlyPertinentCultures = settings.Settings.ShowOnlyPertinentCultures;
            part.ShowLabel = settings.Settings.ShowLabel;
            settings = null;
            var urlPrefix = _workContextAccessor.GetContext().Resolve<ShellSettings>().RequestUrlPrefix;
            if (!String.IsNullOrWhiteSpace(urlPrefix)) {
                cleanUrl = cleanUrl.StartsWith(urlPrefix, StringComparison.OrdinalIgnoreCase) ? cleanUrl.Substring(urlPrefix.Length) : cleanUrl;
            }
            cleanUrl = HttpUtility.UrlDecode(cleanUrl);
            cleanUrl = cleanUrl.StartsWith("/") ? cleanUrl.Substring(1) : cleanUrl;
            var isHomePage = String.IsNullOrWhiteSpace(cleanUrl);
            part.TranslatedCultures = _localizableContentService.AvailableTranslations(cleanUrl, isHomePage);


            part.UserCulture = _extendedCultureService.GetExtendedCulture(_cultureManager.GetCurrentCulture(_workContextAccessor.GetContext().HttpContext));

            return ContentShape("Parts_CulturePicker", () => shapeHelper.Parts_CulturePicker(AvailableCultures: part.AvailableCultures, TranslatedCultures: part.TranslatedCultures, UserCulture: part.UserCulture, ShowOnlyPertinentCultures: part.ShowOnlyPertinentCultures, ShowLabel: part.ShowLabel));
        }
Esempio n. 2
0
        protected override DriverResult Display(CulturePickerPart part, string displayType, dynamic shapeHelper)
        {
            part.AvailableCultures = _cultureManager.ListCultures();
            part.UserCulture       = _cultureManager.GetCurrentCulture(_workContextAccessor.GetContext().HttpContext);

            return(ContentShape("Parts_CulturePicker", () => shapeHelper.Parts_CulturePicker(AvailableCultures: part.AvailableCultures, UserCulture: part.UserCulture)));
        }
Esempio n. 3
0
 public Func <WorkContext, T> Get <T>(string name)
 {
     if (name == "CurrentCulture")
     {
         return(ctx => (T)(object)cultureManager.GetCurrentCulture(ctx.HttpContext));
     }
     return(null);
 }
 public LocalizationBucket(ICultureManager cultureManager, IWorkContextAccessor workContextAccessor)
 {
     var currentCultureName = cultureManager.GetCurrentCulture(workContextAccessor.GetContext().HttpContext);
     var defaultCultureName = cultureManager.GetSiteCulture();
     CurrentCulture = cultureManager.GetCultureByName(currentCultureName);
     DefaultCulture = cultureManager.GetCultureByName(defaultCultureName);
     IsCurrentCultureDefault = CurrentCulture != null && CurrentCulture.Id == DefaultCulture.Id;
 }
Esempio n. 5
0
            public LocalizationBucket(ICultureManager cultureManager, IWorkContextAccessor workContextAccessor)
            {
                var currentCultureName = cultureManager.GetCurrentCulture(workContextAccessor.GetContext().HttpContext);
                var defaultCultureName = cultureManager.GetSiteCulture();

                CurrentCulture          = cultureManager.GetCultureByName(currentCultureName);
                DefaultCulture          = cultureManager.GetCultureByName(defaultCultureName);
                IsCurrentCultureDefault = CurrentCulture != null && CurrentCulture.Id == DefaultCulture.Id;
            }
Esempio n. 6
0
        public IEnumerable <MenuItem> Filter(IEnumerable <MenuItem> menuItems)
        {
            string defaultSiteCulture = _siteService.GetSiteSettings().As <SiteSettingsPart>().SiteCulture;

            string currentCulture = _cultureManager.GetCurrentCulture(_workContextAccessor.GetContext().HttpContext);

            foreach (MenuItem menuItem in menuItems)
            {
                if ((currentCulture == defaultSiteCulture && menuItem.Culture == null) ||
                    menuItem.Culture == currentCulture)
                {
                    yield return(menuItem);
                }
            }
        }
Esempio n. 7
0
        public IEnumerable <MenuItem> Filter(IEnumerable <MenuItem> menuItems)
        {
            string currentCulture = _cultureManager.GetCurrentCulture(_workContextAccessor.GetContext().HttpContext);

            foreach (MenuItem menuItem in menuItems)
            {
                ILocalizableAspect localizationPart = menuItem.Content.Is <ContentMenuItemPart>()
                                                          ? menuItem.Content.As <ContentMenuItemPart>().Content.As <ILocalizableAspect>()
                                                          : menuItem.Content.As <ILocalizableAspect>();
                if (localizationPart == null ||
                    localizationPart.Culture == null ||
                    localizationPart.Culture == currentCulture)
                {
                    yield return(menuItem);
                }
            }
        }
Esempio n. 8
0
        public IEnumerable <MenuItem> Filter(IEnumerable <MenuItem> menuItems)
        {
            string defaultSiteCulture = _siteService.GetSiteSettings().As <SiteSettingsPart>().SiteCulture;

            string currentCulture = _cultureManager.GetCurrentCulture(_workContextAccessor.GetContext().HttpContext);

            foreach (MenuItem menuItem in menuItems)
            {
                if (((menuItem.Culture == null) &&
                     ((_homePageService.GetSettings().MenuMode == Models.MenuFilterMode.NonLocalizedAreAll) ||
                      ((_homePageService.GetSettings().MenuMode == Models.MenuFilterMode.NonLocalizedAreSite) && (currentCulture == defaultSiteCulture)))) ||
                    menuItem.Culture == currentCulture)
                {
                    yield return(menuItem);
                }
            }
        }
        public ActionResult Translate(int id, string to)
        {
            var contentItem = _contentManager.Get(id, VersionOptions.Latest);

            // only support translations from the site culture, at the moment at least
            if (contentItem == null)
            {
                return(HttpNotFound());
            }

            if (!contentItem.Is <LocalizationPart>() || contentItem.As <LocalizationPart>().MasterContentItem != null)
            {
                var metadata = _contentManager.GetItemMetadata(contentItem);
                return(RedirectToAction(Convert.ToString(metadata.EditorRouteValues["action"]), metadata.EditorRouteValues));
            }

            var siteCultures    = _cultureManager.ListCultures().Where(s => s != _localizationService.GetContentCulture(contentItem) && s != _cultureManager.GetSiteCulture());
            var selectedCulture = siteCultures.SingleOrDefault(s => string.Equals(s, to, StringComparison.OrdinalIgnoreCase))
                                  ?? _cultureManager.GetCurrentCulture(HttpContext); // could be null but the person doing the translating might be translating into their current culture

            //todo: need a better solution for modifying some parts when translating - or go with a completely different experience

            /*
             * if (contentItem.Has<RoutePart>()) {
             *  RoutePart routePart = contentItem.As<RoutePart>();
             *  routePart.Slug = string.Format("{0}{2}{1}", routePart.Slug, siteCultures.Any(s => string.Equals(s, selectedCulture, StringComparison.OrdinalIgnoreCase)) ? selectedCulture : "", !string.IsNullOrWhiteSpace(routePart.Slug) ? "-" : "");
             *  routePart.Path = null;
             * }*/

            if (contentItem.As <LocalizationPart>().Culture != null)
            {
                contentItem.As <LocalizationPart>().Culture.Culture = null;
            }
            var model = new AddLocalizationViewModel {
                Id = id,
                SelectedCulture = selectedCulture,
                SiteCultures    = siteCultures,
                Content         = _contentManager.BuildEditor(contentItem)
            };

            // Cancel transaction so that the routepart is not modified.
            Services.TransactionManager.Cancel();

            return(View(model));
        }
        public ActionResult Index()
        {
            HttpContextBase httpContext = _orchardServices.WorkContext.HttpContext;

            RouteValueDictionary homepageRouteValueDictionary = _aliasService.Get(string.Empty);
            int routeId = Convert.ToInt32(homepageRouteValueDictionary["Id"]);

            ContentItem content = _orchardServices.ContentManager.Get(routeId, VersionOptions.Published);

            if (content == null)
            {
                return(new HttpNotFoundResult());
            }

            string        currentCultureName = _cultureManager.GetCurrentCulture(httpContext);
            AutoroutePart localizedRoutePart;

            //content may not have localized version and we use "Try" approach
            if (_localizableContentService.TryFindLocalizedRoute(content, currentCultureName, out localizedRoutePart))
            {
                string returnUrl = localizedRoutePart.Path;

                //support for Orchard < 1.6
                //TODO: discontinue in 2013 Q2
                Version orchardVersion = Utils.GetOrchardVersion();
                if (orchardVersion < new Version(1, 6))
                {
                    returnUrl = Url.Encode(returnUrl);
                }
                else
                {
                    if (!returnUrl.StartsWith("~/"))
                    {
                        returnUrl = "~/" + returnUrl;
                    }
                }

                return(this.RedirectLocal(returnUrl, (Func <ActionResult>)null));
            }

            dynamic model = _orchardServices.ContentManager.BuildDisplay(content);

            return(new ShapeResult(this, model));
        }
Esempio n. 11
0
        public ActionResult Culture()
        {
            //todo: class and/or method attributes for our auth?
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage settings")))
            {
                return(new HttpUnauthorizedResult());
            }

            var model = new SiteCulturesViewModel {
                CurrentCulture = _cultureManager.GetCurrentCulture(HttpContext),
                SiteCultures   = _cultureManager.ListCultures(),
            };

            model.AvailableSystemCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
                                            .Select(ci => ci.Name)
                                            .Where(s => !model.SiteCultures.Contains(s));

            return(View(model));
        }
Esempio n. 12
0
        public ActionResult Translate(int id, string to)
        {
            var contentItem = _contentManager.Get(id, VersionOptions.Latest);

            if (contentItem == null)
            {
                return(HttpNotFound());
            }

            if (!contentItem.Is <LocalizationPart>() || contentItem.As <LocalizationPart>().MasterContentItem != null || string.IsNullOrEmpty(to))
            {
                var metadata = _contentManager.GetItemMetadata(contentItem);
                return(RedirectToAction(Convert.ToString(metadata.EditorRouteValues["action"]), metadata.EditorRouteValues));
            }

            var contentCulture = _localizationService.GetContentCulture(contentItem);

            var potCultures     = _cultureManager.ListCultures().Where(s => s != contentCulture);
            var selectedCulture = potCultures.SingleOrDefault(s => string.Equals(s, to, StringComparison.OrdinalIgnoreCase))
                                  ?? _cultureManager.GetCurrentCulture(HttpContext); // could be null but the person doing the translating might be translating into their current culture


            var lPs = _cultureService.GetLocalizations(contentItem.As <LocalizationPart>(), VersionOptions.Latest);
            // the existing culture are the real existing ones and the one we are creating
            var siteCultures = lPs.Select(p => p.Culture.Culture).Union(new string[] { selectedCulture }).Distinct().ToList();    // necessary because the culture in cultureRecord will be set to null before expr resolution

            if (contentItem.As <LocalizationPart>().Culture != null)
            {
                contentItem.As <LocalizationPart>().Culture.Culture = null;
            }
            var model = new AddLocalizationViewModel {
                Id = id,
                SelectedCulture = selectedCulture,
                SiteCultures    = siteCultures,
                Content         = _contentManager.BuildEditor(contentItem)
            };

            // Cancel transaction so that the CultureRecord is not modified.
            Services.TransactionManager.Cancel();

            return(View(model));
        }
        public void Evaluate(ConditionEvaluationContext evaluationContext)
        {
            if (!String.Equals(evaluationContext.FunctionName, "lang", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var culture     = evaluationContext.Arguments.Cast <String>();
            var userCulture = _cultureManager.GetCurrentCulture(_workContextAccessor.GetContext().HttpContext).ToLower();


            var matches = culture.Any(c => c.ToLower() == userCulture.ToLower());

            if (matches)
            {
                evaluationContext.Result = true;
                return;
            }

            evaluationContext.Result = false;
            return;
        }
        IPageOfItems <T> ISearchService.Query <T>(string query, int page, int?pageSize, bool filterCulture, string index, string[] searchFields, Func <ISearchHit, T> shapeResult)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                return(new PageOfItems <T>(Enumerable.Empty <T>()));
            }

            var searchBuilder = Search(index).Parse(searchFields, query);

            if (filterCulture)
            {
                var culture = _cultureManager.GetCurrentCulture(Services.WorkContext.HttpContext);

                // use LCID as the text representation gets analyzed by the query parser
                searchBuilder
                .WithField("culture", CultureInfo.GetCultureInfo(culture).LCID)
                .AsFilter();
            }

            var totalCount = searchBuilder.Count();

            if (pageSize != null)
            {
                searchBuilder = searchBuilder
                                .Slice((page > 0 ? page - 1 : 0) * (int)pageSize, (int)pageSize);
            }

            var searchResults = searchBuilder.Search();

            var pageOfItems = new PageOfItems <T>(searchResults.Select(shapeResult))
            {
                PageNumber     = page,
                PageSize       = pageSize != null ? (int)pageSize : totalCount,
                TotalItemCount = totalCount
            };

            return(pageOfItems);
        }
Esempio n. 15
0
 public void CultureManagerReturnsCultureFromSelector()
 {
     Assert.That(_cultureManager.GetCurrentCulture(null), Is.EqualTo("en-US"));
 }
Esempio n. 16
0
 public string GetCurrentCulture()
 {
     return(_cultureManager.GetCurrentCulture(_workContextAccessor.GetContext().HttpContext));
 }
Esempio n. 17
0
 public void CultureManagerReturnsCultureFromWorkContext()
 {
     _stubWorkContext.CultureName = "nl-NL";
     Assert.That(_cultureManager.GetCurrentCulture(null), Is.EqualTo("nl-NL"));
 }
Esempio n. 18
0
        public string GetCurrentCulture(System.Web.HttpContextBase requestContext)
        {
            var cultureName = _underlyingCultureManager.GetCurrentCulture(requestContext);

            return(LookupForMasterCulture(cultureName));
        }
 public string GetCurrentCulture()
 {
     return(_cultureManager.GetCurrentCulture(_orchardServices.WorkContext.HttpContext));
 }