Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the questions/phrases
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private IEnumerable <TranslatablePhrase> GetPhrases()
        {
            var processedCategories = new Dictionary <string, int>();

            for (var iSection = 0; iSection < m_sections.Items.Length; iSection++)
            {
                var section = m_sections.Items[iSection];
                Debug.Assert(section.Categories.Distinct(CategoryComparer.AreSame).Count() == section.Categories.Length,
                             "Section contains a repeated category.");
                foreach (var category in section.Categories)
                {
                    TranslatablePhrase phrase;

                    // In the event of an unnamed non-overview category (only possible in tests),
                    // treat it as "Details" (or whatever Category 1 happens to be).
                    var categoryIndex = category.IsOverview ? 0 : 1;
                    if (category.Type != null)
                    {
                        var lcCategory = category.Type.ToLowerInvariant();
                        if (!processedCategories.TryGetValue(lcCategory, out categoryIndex))
                        {
                            phrase = new TranslatablePhrase(new SimpleQuestionKey(category.Type), -1, -1, processedCategories.Count);
                            phrase.m_parts.Add(m_manager.GetOrCreatePart(PhraseParser.GetWordsInString(lcCategory), phrase, false));
                            yield return(phrase);

                            // 0 is reserved for "overview", so we can't use that for non-overview categories.
                            categoryIndex = category.IsOverview ? 0 : Math.Max(1, processedCategories.Count);
                            processedCategories[lcCategory] = categoryIndex;
                        }
                    }

                    for (int iQuestion = 0; iQuestion < category.Questions.Count; iQuestion++)
                    {
                        Question q = category.Questions[iQuestion];
                        if (q.ScriptureReference == null)
                        {
                            q.ScriptureReference = section.ScriptureReference;
                            q.StartRef           = section.StartRef;
                            q.EndRef             = section.EndRef;
                        }

                        Debug.Assert(categoryIndex >= 0);
                        phrase = new TranslatablePhrase(q, iSection, categoryIndex, iQuestion);
                        if (!phrase.IsExcluded)
                        {
                            InitializePhraseParts(phrase);
                        }
                        yield return(phrase);
                    }
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the questions/phrases
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private IEnumerable <TranslatablePhrase> GetPhrases()
        {
            HashSet <string>   processedCategories = new HashSet <string>();
            TranslatablePhrase phrase;
            int categoryType;

            foreach (Section section in m_sections.Items)
            {
                for (int iCat = 0; iCat < section.Categories.Length; iCat++)
                {
                    Category category = section.Categories[iCat];
                    categoryType = iCat;
                    if (iCat == 0 && !category.IsOverview)                     // 0 is reserved for "overview", so we can't use that for non-overview categories.
                    {
                        categoryType++;
                    }

                    if (category.Type != null)
                    {
                        string lcCategory = category.Type.ToLowerInvariant();
                        if (!processedCategories.Contains(lcCategory))
                        {
                            phrase = new TranslatablePhrase(new SimpleQuestionKey(category.Type), -1, processedCategories.Count);
                            phrase.m_parts.Add(m_manager.GetOrCreatePart(PhraseParser.GetWordsInString(lcCategory), phrase, false));
                            yield return(phrase);

                            processedCategories.Add(lcCategory);
                        }
                    }

                    for (int iQuestion = 0; iQuestion < category.Questions.Count; iQuestion++)
                    {
                        Question q = category.Questions[iQuestion];
                        if (q.ScriptureReference == null)
                        {
                            q.ScriptureReference = section.ScriptureReference;
                            q.StartRef           = section.StartRef;
                            q.EndRef             = section.EndRef;
                        }
                        phrase = new TranslatablePhrase(q, categoryType, iQuestion + 1);
                        if (!phrase.IsExcluded)
                        {
                            InitializePhraseParts(phrase);
                        }
                        yield return(phrase);
                    }
                }
            }
        }