internal IReadOnlyList <TranslationUnit> GetQuestionSubgroupTranslationUnits(Question question, LocalizableStringType type) { switch (type) { case LocalizableStringType.Alternate: case LocalizableStringType.Answer: case LocalizableStringType.Note: UIDataString key = new UIQuestionDataString(question, true, false); return(Localizations.FindQuestionGroup(key)?.GetQuestionSubGroup(type)?.TranslationUnits); default: throw new ArgumentOutOfRangeException(); } }
internal void GenerateOrUpdateFromMasterQuestions(QuestionSections questions, List <XmlTranslation> existingTxlTranslations = null, bool retainOnlyTranslatedStrings = false) { InitializeLookupTable(); // Note: there are two possible sources for existing localized translations of strings: either a Transcelerator project // (the list passed into this method), or the content read from a previous version of the file represented by this accessor. var existingLocalizations = XliffRoot.File.Body; existingLocalizations.DeleteGroupsWithoutLocalizations(); if (existingLocalizations.Groups == null) { existingLocalizations = null; } if (existingTxlTranslations == null && retainOnlyTranslatedStrings) { return; } InitializeLocalizations(); if (existingTxlTranslations == null) { if (existingLocalizations == null) { AddTranslationUnit = (group, data) => group.AddTranslationUnit(data); } else { AddTranslationUnit = (group, data) => { var tu = existingLocalizations.GetStringLocalization(data); if (tu == null) { group.AddTranslationUnit(data); } else { group.AddTranslationUnit(tu); } }; } } else { if (existingLocalizations == null) { AddTranslationUnit = (group, data) => { group.AddTranslationUnit(data, LookupTranslation(existingTxlTranslations, data)); }; } else { AddTranslationUnit = (group, data) => { var tu = existingLocalizations.GetStringLocalization(data); if (tu == null) { group.AddTranslationUnit(data, LookupTranslation(existingTxlTranslations, data)); } else { group.AddTranslationUnit(tu); } }; } } UIDataString key; foreach (var section in questions.Items) { var sectionGroup = new Group { Id = FileBody.GetSectionId(section) }; Localizations.Groups.Add(sectionGroup); key = new UISectionHeadDataString(new SectionInfo(section)); AddTranslationUnit(sectionGroup, key); foreach (Category category in section.Categories) { var categoryGroup = sectionGroup.AddSubGroup(category.Type); if (category.Type != null) { if (!Localizations.Categories.TranslationUnits.Any(tu => tu.English == category.Type)) { key = new UISimpleDataString(category.Type, LocalizableStringType.Category); AddTranslationUnit(Localizations.Categories, key); } } foreach (Question q in category.Questions.Where(q => !String.IsNullOrWhiteSpace(q.Text))) { if (q.ScriptureReference == null) { q.ScriptureReference = section.ScriptureReference; q.StartRef = section.StartRef; q.EndRef = section.EndRef; } // The following line handles the unusual case of the same question twice in the same verse. var questionGroup = categoryGroup.SubGroups?.SingleOrDefault(qg => qg.Id == $"{FileBody.kQuestionIdPrefix}{q.ScriptureReference}+{q.PhraseInUse}"); if (questionGroup == null) { questionGroup = categoryGroup.AddSubGroup($"{FileBody.kQuestionIdPrefix}{q.ScriptureReference}+{q.PhraseInUse}"); key = new UIQuestionDataString(q, true, false); AddTranslationUnit(questionGroup, key); } AddAlternatesSubgroupAndLocalizableStringsIfNeeded(q, questionGroup); AddAnswerOrNoteSubgroupAndLocalizableStringsIfNeeded(q, questionGroup, LocalizableStringType.Answer, qu => qu.Answers); AddAnswerOrNoteSubgroupAndLocalizableStringsIfNeeded(q, questionGroup, LocalizableStringType.Note, qu => qu.Notes); } } } if (retainOnlyTranslatedStrings) { Localizations.DeleteGroupsWithoutLocalizations(); } AddTranslationUnit = null; }