コード例 #1
0
        protected override DriverResult Display(LocalizationPart part, string displayType, dynamic shapeHelper)
        {
            var masterId = part.MasterContentItem != null
                   ? part.MasterContentItem.Id
                   : part.Id;
            var localizations   = _cultureService.GetLocalizations(part, VersionOptions.Latest).ToList();
            var siteCulture     = _cultureService.GetSiteCulture();
            var selectedCulture = part.Culture != null ? part.Culture.Culture : (part.Id == 0 ? siteCulture : null);
            var sC           = _cultureService.ListCultures();
            var siteCultures = sC.Where(c => c.Culture != null)
                               .Select(c => c.Culture)
                               .Where(s => !localizations.Select(l => l.Culture.Culture).Contains(s));

            return(Combined(
                       ContentShape("Parts_ExLocalization_ContentTranslations",
                                    () => shapeHelper.Parts_ExLocalization_ContentTranslations(MasterId: masterId, Localizations: localizations.Where(c => c.Culture.Culture != selectedCulture))),
                       ContentShape("Parts_ExLocalization_ContentTranslations_Summary",
                                    () => shapeHelper.Parts_ExLocalization_ContentTranslations_Summary(MasterId: masterId,
                                                                                                       ShowAddTranslation: _cultureService.ListCultures().Select(c => c.Culture).Where(s => s != siteCulture && !localizations.Select(l => l.Culture.Culture).Contains(s)).Any(),
                                                                                                       SelectedCulture: selectedCulture,
                                                                                                       ContentItem: part.ContentItem,
                                                                                                       SiteCultures: siteCultures,
                                                                                                       Localizations: localizations.Where(c => c.Culture.Culture != selectedCulture))),
                       ContentShape("Parts_ExLocalization_ContentTranslations_SummaryAdmin",
                                    () => shapeHelper.Parts_ExLocalization_ContentTranslations_SummaryAdmin(MasterId: masterId,
                                                                                                            MasterContentItem: part.MasterContentItem,
                                                                                                            ShowAddTranslation: _cultureService.ListCultures().Select(c => c.Culture).Where(s => s != siteCulture && !localizations.Select(l => l.Culture.Culture).Contains(s)).Any(),
                                                                                                            SelectedCulture: selectedCulture,
                                                                                                            SiteCultures: siteCultures,
                                                                                                            ContentItem: part.ContentItem,
                                                                                                            Localizations: localizations.Where(c => c.Culture.Culture != selectedCulture)))
                       ));
        }
コード例 #2
0
        public ActionResult NotTranslated(string culture, int?id)
        {
            ViewBag.Culture       = culture ?? _cultureService.GetCurrentCulture();
            ViewBag.ContentItem   = id.HasValue ? _orchardServices.ContentManager.Get(id.Value) : null;
            ViewBag.Localizations = ViewBag.ContentItem != null?_cultureService.GetLocalizations((ViewBag.ContentItem as IContent).As <LocalizationPart>(), VersionOptions.Latest).ToArray() : new LocalizationPart[0];

            return(View("NotTranslated"));
        }
コード例 #3
0
        protected override DriverResult Display(CookieCulturePickerPart part, string displayType, dynamic shapeHelper)
        {
            var urlHelper          = new UrlHelper(_orchardServices.WorkContext.HttpContext.Request.RequestContext);
            var cookieCultureItems = new List <CookieCultureItemViewModel>();
            // Is content item shown?
            var contentItem    = _cultureService.GetCurrentContentItem();
            var currentCulture = _cultureService.GetCurrentCulture();
            var returnUrl      = _orchardServices.WorkContext.HttpContext.Request.Url.LocalPath;
            var localizations  = contentItem != null?_cultureService.GetLocalizations(contentItem.As <LocalizationPart>(), VersionOptions.Latest).ToList() : null;

            if (!string.IsNullOrWhiteSpace(returnUrl) && returnUrl.IndexOf("/NotTranslated", StringComparison.OrdinalIgnoreCase) > 0)
            {
                returnUrl = urlHelper.Content("~/");
            }

            foreach (var cultureItem in _cultureService.ListCultures())
            {
                var cookieCultureItem = new CookieCultureItemViewModel
                {
                    CultureItem = cultureItem,
                    Current     = string.Equals(currentCulture, cultureItem.Culture, StringComparison.OrdinalIgnoreCase),
                    ReturnUrl   = returnUrl,
                    Rel         = contentItem == null ? "nofollow" : null
                };
                if (localizations != null)
                {
                    var localizedContentItem = localizations.Where(p => string.Equals(p.Culture.Culture, cultureItem.Culture, StringComparison.OrdinalIgnoreCase)).Select(p => p.ContentItem).FirstOrDefault();
                    var metadata             = localizedContentItem != null?localizedContentItem.ContentManager.GetItemMetadata(localizedContentItem) : null;

                    if (metadata != null && metadata.DisplayRouteValues != null)
                    {
                        cookieCultureItem.ReturnUrl = urlHelper.Content(urlHelper.RouteUrl(metadata.DisplayRouteValues));
                    }
                    else
                    {
                        cookieCultureItem.ReturnUrl = urlHelper.RouteUrl(new { Area = "RM.Localization", Action = "NotTranslated", Controller = "LocalizedHome", Culture = cultureItem.Culture, Id = contentItem.Id });
                        cookieCultureItem.Rel       = "nofollow";
                    }
                }
                cookieCultureItems.Add(cookieCultureItem);
            }

            if (part.Style == Styles[1])
            {
                return(ContentShape("Parts_CookieCulturePicker", () => shapeHelper.Parts_DropdownCookieCulturePicker(Cultures: cookieCultureItems, CurrentCulture: currentCulture)));
            }
            else
            {
                return(ContentShape("Parts_CookieCulturePicker", () => shapeHelper.Parts_InlineListCookieCulturePicker(Cultures: cookieCultureItems, CurrentCulture: currentCulture)));
            }
        }
コード例 #4
0
ファイル: AdminController.cs プロジェクト: YSRE/SuperRocket
        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));
        }