diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Projections/TermsFilter.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Projections/TermsFilter.cs index 4a020f1ec65..f5cff35789c 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Projections/TermsFilter.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Projections/TermsFilter.cs @@ -6,6 +6,8 @@ using Orchard.ContentManagement; using Orchard.Events; using Orchard.Localization; +using Orchard.Localization.Services; +using Orchard.Taxonomies.Drivers; namespace Orchard.Taxonomies.Projections { public interface IFilterProvider : IEventHandler { @@ -14,10 +16,13 @@ public interface IFilterProvider : IEventHandler { public class TermsFilter : IFilterProvider { private readonly ITaxonomyService _taxonomyService; + private readonly IWorkContextAccessor _workContextAccessor; private int _termsFilterId; - public TermsFilter(ITaxonomyService taxonomyService) { + public TermsFilter(ITaxonomyService taxonomyService, + IWorkContextAccessor workContextAccessor) { _taxonomyService = taxonomyService; + _workContextAccessor = workContextAccessor; T = NullLocalizer.Instance; } @@ -48,13 +53,30 @@ public void ApplyFilter(dynamic context) { int op = Convert.ToInt32(context.State.Operator); var terms = ids.Select(_taxonomyService.GetTerm).ToList(); + + bool.TryParse(context.State.TranslateTerms?.Value, out bool translateTerms); + if (translateTerms && + _workContextAccessor.GetContext().TryResolve(out var localizationService)) { + var localizedTerms = new List(); + foreach (var termPart in terms) { + localizedTerms.AddRange( + localizationService.GetLocalizations(termPart) + .Select(l => l.As())); + } + terms.AddRange(localizedTerms); + terms = terms.Distinct(new TermPartComparer()).ToList(); + } + var allChildren = new List(); + bool.TryParse(context.State.ExcludeChildren?.Value, out bool excludeChildren); foreach (var term in terms) { - bool.TryParse(context.State.ExcludeChildren?.Value, out bool excludeChildren); - if (!excludeChildren) + if (term == null) { + continue; + } + allChildren.Add(term); + if (!excludeChildren) { allChildren.AddRange(_taxonomyService.GetChildren(term)); - if (term != null) - allChildren.Add(term); + } } allChildren = allChildren.Distinct().ToList(); diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Projections/TermsFilterForms.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Projections/TermsFilterForms.cs index 8ce95cdb347..6bbcd947f1c 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Projections/TermsFilterForms.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Projections/TermsFilterForms.cs @@ -53,6 +53,11 @@ public void Describe(dynamic context) { Id: "ExcludeChildren", Name: "ExcludeChildren", Title: T("Automatically exclude children terms in filtering"), Value: "true" + ), + _TranslateTerms: Shape.Checkbox( + Id: "TranslateTerms", Name: "TranslateTerms", + Title: T("Automatically include terms' localizations in filtering"), + Value: "true" ) );