66using Orchard . ContentManagement ;
77using Orchard . Events ;
88using Orchard . Localization ;
9+ using Orchard . Localization . Services ;
10+ using Orchard . Taxonomies . Drivers ;
911
1012namespace Orchard . Taxonomies . Projections {
1113 public interface IFilterProvider : IEventHandler {
@@ -14,10 +16,13 @@ public interface IFilterProvider : IEventHandler {
1416
1517 public class TermsFilter : IFilterProvider {
1618 private readonly ITaxonomyService _taxonomyService ;
19+ private readonly IWorkContextAccessor _workContextAccessor ;
1720 private int _termsFilterId ;
1821
19- public TermsFilter ( ITaxonomyService taxonomyService ) {
22+ public TermsFilter ( ITaxonomyService taxonomyService ,
23+ IWorkContextAccessor workContextAccessor ) {
2024 _taxonomyService = taxonomyService ;
25+ _workContextAccessor = workContextAccessor ;
2126 T = NullLocalizer . Instance ;
2227 }
2328
@@ -48,13 +53,30 @@ public void ApplyFilter(dynamic context) {
4853 int op = Convert . ToInt32 ( context . State . Operator ) ;
4954
5055 var terms = ids . Select ( _taxonomyService . GetTerm ) . ToList ( ) ;
56+
57+ bool . TryParse ( context . State . TranslateTerms ? . Value , out bool translateTerms ) ;
58+ if ( translateTerms &&
59+ _workContextAccessor . GetContext ( ) . TryResolve < ILocalizationService > ( out var localizationService ) ) {
60+ var localizedTerms = new List < TermPart > ( ) ;
61+ foreach ( var termPart in terms ) {
62+ localizedTerms . AddRange (
63+ localizationService . GetLocalizations ( termPart )
64+ . Select ( l => l . As < TermPart > ( ) ) ) ;
65+ }
66+ terms . AddRange ( localizedTerms ) ;
67+ terms = terms . Distinct ( new TermPartComparer ( ) ) . ToList ( ) ;
68+ }
69+
5170 var allChildren = new List < TermPart > ( ) ;
71+ bool . TryParse ( context . State . ExcludeChildren ? . Value , out bool excludeChildren ) ;
5272 foreach ( var term in terms ) {
53- bool . TryParse ( context . State . ExcludeChildren ? . Value , out bool excludeChildren ) ;
54- if ( ! excludeChildren )
73+ if ( term == null ) {
74+ continue ;
75+ }
76+ allChildren . Add ( term ) ;
77+ if ( ! excludeChildren ) {
5578 allChildren . AddRange ( _taxonomyService . GetChildren ( term ) ) ;
56- if ( term != null )
57- allChildren . Add ( term ) ;
79+ }
5880 }
5981
6082 allChildren = allChildren . Distinct ( ) . ToList ( ) ;
0 commit comments