protected override void ProcessItemLanguages(Item item)
        {
            ProcessedList = new List <string>();

            if (IsParameterSpecified(nameof(Language)) || IsParameterSpecified(nameof(ExcludeLanguage)))
            {
                foreach (
                    var langItem in
                    item.Versions.GetVersions(true)
                    .Where(
                        langItem =>
                        LanguageWildcardPatterns.Any(wildcard => wildcard.IsMatch(langItem.Language.Name)))
                    .Where(
                        langItem =>
                        !ExcludeLanguageWildcardPatterns.Any(
                            wildcard => wildcard.IsMatch(langItem.Language.Name))))
                {
                    TrimVersions(langItem);
                }
            }
            else
            {
                TrimVersions(item);
            }
            if (Recurse)
            {
                foreach (Item child in item.Children)
                {
                    ProcessItemLanguages(child);
                }
            }
        }
Example #2
0
        protected override List <Item> LatestVersionInFilteredLanguages(Item item)
        {
            var languagePatterns = new List <WildcardPattern>();
            IEnumerable <string> fullyQualifiedLanguages = new List <string>();

            if (Language != null && Language.Any())
            {
                languagePatterns =
                    Language.Where(lang => lang.Contains('*') || lang.Contains('?')).Select(
                        language =>
                        new WildcardPattern(language,
                                            WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant))
                    .ToList();
                fullyQualifiedLanguages = Language.Where(lang => !lang.Contains('*') && !lang.Contains('?'));
            }


            var publishedLangs = new List <string>();
            var result         = new List <Item>();

            foreach (var langName in fullyQualifiedLanguages)
            {
                var language = LanguageManager.GetLanguage(langName);
                var langItem = item.Database.GetItem(item.ID, language);
                if (!publishedLangs.Contains(langItem.Language.Name))
                {
                    publishedLangs.Add(langItem.Language.Name);
                    result.Add(langItem);
                }
            }

            // if there are any wildcards - filter item in all languages
            if (languagePatterns.Any())
            {
                foreach (
                    var langItem in
                    item.Versions.GetVersions(true).Reverse())
                {
                    // publish latest version of each language
                    if (LanguageWildcardPatterns.Any(wildcard => !publishedLangs.Contains(langItem.Language.Name) &&
                                                     wildcard.IsMatch(langItem.Language.Name)))
                    {
                        publishedLangs.Add(langItem.Language.Name);
                        result.Add(langItem);
                    }
                }
            }
            return(result);
        }