/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the text representation of the back translations for a footnote paragraph. /// </summary> /// <param name="footnotePara">The footnote paragraph.</param> /// <returns> /// text representation of all of the back translations for the footnote paragraph /// </returns> /// ------------------------------------------------------------------------------------ private string GetTextRepresentationOfTrans(StTxtPara footnotePara) { string transRepresentation = string.Empty; CmTranslation trans = (CmTranslation)footnotePara.GetBT(); if (trans == null) { return(transRepresentation); } List <int> transWs = m_cache.GetUsedScriptureTransWsForPara(footnotePara.Hvo); foreach (int ws in transWs) { ITsString tss = trans.Translation.GetAlternativeTss(ws); if (tss != null && tss.Length > 0) { LgWritingSystem lgws = new LgWritingSystem(m_cache, ws); transRepresentation += "<TRANS WS='" + lgws.ICULocale + "'>"; transRepresentation += GetTextRepresentationOfTsString(tss); transRepresentation += "</TRANS>"; } } return(transRepresentation); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Mark specified back translation as unfinished. This should be called when the back /// translation is modified. /// </summary> /// <param name="translation">The translation.</param> /// <param name="hvoWs">The hvo of the current back translation writing system</param> /// ------------------------------------------------------------------------------------ private void MarkCurrentBackTranslationAsUnfinished(CmTranslation translation, int hvoWs) { if (m_cache.IsRealObject(hvoWs, LgWritingSystem.kclsidLgWritingSystem)) { // We have confirmed that this hvo is for a writing system. // set the specified alternate writing system to unfinished. string status = translation.Status.GetAlternative(hvoWs); if (status != null && status != BackTranslationStatus.Unfinished.ToString()) translation.Status.SetAlternative(BackTranslationStatus.Unfinished.ToString(), hvoWs); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Update the status of a back translation if it was modified (from finished or checked /// to unfinished). /// </summary> /// <param name="hvoTrans">A translation that was changed (probably a back translation) /// </param> /// <param name="ivMin">in CmTranslation, this is the hvo of the writing system of the /// string that has changed</param> /// <param name="cvIns">the number of items inserted?</param> /// <param name="cvDel">the number of items deleted?</param> /// ------------------------------------------------------------------------------------ protected override void DoEffectsOfPropChange(int hvoTrans, int ivMin, int cvIns, int cvDel) { CmTranslation trans = new CmTranslation(m_cache, hvoTrans); if (trans.TypeRA.Guid == LangProject.kguidTranBackTranslation) MarkCurrentBackTranslationAsUnfinished(trans, ivMin); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Looks to see if we currently have a translation of the given type, returning it if /// we do. If no such CmTranslation exists, a new one is created and returned. /// </summary> /// <param name="transType">The CmPossibility representing the type of translation to /// get or create</param> /// <returns>CmTranslation of the given type</returns> /// ------------------------------------------------------------------------------------ public ICmTranslation GetOrCreateTrans(ICmPossibility transType) { Debug.Assert(transType != null); ICmTranslation trans = GetTrans(transType.Guid); if (trans == null) { // we need to create an empty translation if one does not exist. IActionHandler acth = m_cache.ActionHandlerAccessor; SuppressSubTasks suppressSubTasks = null; // We don't want to create an undo task if there isn't one already open, so we // set the ActionHandler to null while we create the back translation. bool fNewTransaction = false; string sSavePointName = string.Empty; IOleDbEncap dbAccess = m_cache.DatabaseAccessor; if (acth != null && acth.CurrentDepth == 0) { suppressSubTasks = new SuppressSubTasks(m_cache); } else if (dbAccess != null && !dbAccess.IsTransactionOpen()) { // Set a save point in case there is a problem with the database server. // If there is a problem adding the translation or setting the type, this // transaction will be rolled back rather than not completely initializing // the translation. dbAccess.SetSavePointOrBeginTrans(out sSavePointName); fNewTransaction = true; } try { trans = new CmTranslation(); TranslationsOC.Add(trans); trans.TypeRA = transType; } finally { if (suppressSubTasks != null) suppressSubTasks.Dispose(); } if (fNewTransaction) dbAccess.CommitTrans(); } return trans; }
/// ------------------------------------------------------------------------------------ /// <summary> /// This is the main interesting method of displaying objects and fragments of them. /// A Scripture is displayed by displaying its Books; /// and a Book is displayed by displaying its Title and Sections; /// and a Section is diplayed by displaying its Heading and Content; /// which are displayed by using the standard view constructor for StText. /// </summary> /// <param name="vwenv"></param> /// <param name="hvo"></param> /// <param name="frag"></param> /// ------------------------------------------------------------------------------------ public override void Display(IVwEnv vwenv, int hvo, int frag) { CheckDisposed(); switch(frag) { case (int)FootnoteFrags.kfrScripture: case (int)ScrFrags.kfrScripture: { // This fragment should only be used on full refresh - clear the user prompt // flags so they will be shown again. ClearUserPromptUpdates(); // We add this lazy - we will expand some of it immediately, but the non- // visible parts will remain lazy! vwenv.NoteDependency(new int[]{m_cache.LangProject.TranslatedScriptureOAHvo}, new int[]{(int)Scripture.ScriptureTags.kflidScriptureBooks}, 1); vwenv.AddLazyVecItems(BooksTag, this, frag == (int)ScrFrags.kfrScripture ? (int)ScrFrags.kfrBook : (int)FootnoteFrags.kfrBook); // Add a 48 point gap at the bottom of the view if (!PrintLayout && (frag != (int)FootnoteFrags.kfrScripture)) vwenv.AddSimpleRect(ColorUtil.ConvertColorToBGR(BackColor), -1, 48000, 0); break; } case (int)ScrFrags.kfrBook: { vwenv.OpenDiv(); vwenv.AddObjProp((int)ScrBook.ScrBookTags.kflidTitle, this, (int)StTextFrags.kfrText); vwenv.AddLazyVecItems((int)ScrBook.ScrBookTags.kflidSections, this, (int)ScrFrags.kfrSection); // Add a 48 point gap at the bottom of the view if (!PrintLayout && m_fShowTailingSpace) vwenv.AddSimpleRect(ColorUtil.ConvertColorToBGR(BackColor), -1, 48000, 0); if (!PrintLayout) InsertBookSeparator(hvo, vwenv); vwenv.CloseDiv(); break; } case (int)ScrFrags.kfrSection: { vwenv.OpenDiv(); vwenv.AddObjProp((int)ScrSection.ScrSectionTags.kflidHeading, this, (int)StTextFrags.kfrText); vwenv.AddObjProp((int)ScrSection.ScrSectionTags.kflidContent, this, (int)StTextFrags.kfrText); vwenv.CloseDiv(); break; } case (int)StTextFrags.kfrPara: if (PrintLayout || !m_fDisplayInTable) { // We are displaying Scripture or a print layout view base.Display(vwenv, hvo, frag); } else { // We are displaying a back translation or Scripture in draftview in a table // Open a table to display the BT para in column 1, and the icon in column 2. VwLength vlTable; // we use this to specify that the table takes 100% of the width. vlTable.nVal = 10000; vlTable.unit = VwUnit.kunPercent100; VwLength vlColumn; // and this one to specify 90% for the text vlColumn.nVal = DisplayTranslation ? 9000 : 10000; vlColumn.unit = VwUnit.kunPercent100; int nColumns = DisplayTranslation ? 2 : 1; vwenv.OpenTable(nColumns, // One or two columns. vlTable, // Table uses 100% of available width. 0, // Border thickness. VwAlignment.kvaLeft, // Default alignment. VwFramePosition.kvfpVoid, // No border. //VwFramePosition.kvfpBox, //VwRule.kvrlAll, // rule lines between cells VwRule.kvrlNone, 0, //No space between cells. 0, //No padding inside cells. false); // Specify column widths. The first argument is the number of columns, // not a column index. vwenv.MakeColumns(nColumns, vlColumn); vwenv.OpenTableBody(); vwenv.OpenTableRow(); // Display paragraph in the first cell vwenv.OpenTableCell(1, 1); InsertParagraphBody(vwenv, hvo, frag, true, ContentType, this); vwenv.CloseTableCell(); if (DisplayTranslation) { // Stylesheet should never be null for a VC that displays BTs, but to be safe... Debug.Assert (m_stylesheet != null); if (m_stylesheet != null) { StPara para = new StPara(m_cache, hvo); ITsTextProps styleRules = para.StyleRules; if (styleRules == null) { Debug.Fail("Style Rules should not be null"); styleRules = NormalStyle; } string paraStyleName = styleRules.GetStrPropValue((int)FwTextPropType.ktptNamedStyle); ITsTextProps ttp = m_stylesheet.GetStyleRgch(0, paraStyleName); Debug.Assert(ttp != null); if (ttp != null) { int var; int spaceBefore = ttp.GetIntPropValues((int)FwTextPropType.ktptSpaceBefore, out var); if (spaceBefore > 0) vwenv.set_IntProperty((int)FwTextPropType.ktptPadTop, var, spaceBefore); } } // BT status icon in the next cell, not editable vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable); vwenv.OpenTableCell(1, 1); vwenv.AddObjVec((int)StTxtPara.StTxtParaTags.kflidTranslations, this, (int)ScrFrags.kfrBtTranslationStatus); vwenv.CloseTableCell(); } // Close table vwenv.CloseTableRow(); vwenv.CloseTableBody(); vwenv.CloseTable(); } break; case (int)ScrFrags.kfrBtTranslationStatus: { CmTranslation trans = new CmTranslation(m_cache, hvo); if (trans != null) { string status = trans.Status.GetAlternative(m_wsDefault); stdole.IPicture picture; if (status == BackTranslationStatus.Checked.ToString()) picture = m_CheckedPic; else if (status == BackTranslationStatus.Finished.ToString()) picture = m_FinishedPic; else picture = m_UnfinishedPic; vwenv.OpenDiv(); vwenv.AddPicture(picture, -1, 0, 0); vwenv.NoteDependency(new int[] {hvo}, new int[] {(int)CmTranslation.CmTranslationTags.kflidStatus}, 1); vwenv.CloseDiv(); } } break; default: base.Display(vwenv, hvo, frag); break; } }
public void BackTranslationNonInterleaved_ParallelPassage() { m_importer.Settings.ImportTranslation = true; m_importer.Settings.ImportBackTranslation = true; m_importer.Settings.ImportBookIntros = true; // ************** process a \id segment, test MakeBook() method ********************* m_importer.TextSegment.FirstReference = new BCVRef(1, 0, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 0, 0); // Set up the vernacular Scripture m_importer.ProcessSegment("", @"\id"); // no text provided in segment, just the refs m_importer.ProcessSegment("Titulo ", @"\mt"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 0); m_importer.ProcessSegment("", @"\c"); m_importer.ProcessSegment("Primera Seccion ", @"\s"); m_importer.ProcessSegment("(Lc. 3.23-38)", @"\r"); m_importer.ProcessSegment("", @"\p"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 1); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 1); m_importer.ProcessSegment("Primer versiculo ", @"\v"); IScrBook genesis = m_importer.ScrBook; Assert.AreEqual(1, genesis.SectionsOS.Count); // minor sanity check // Now test ability to import a non-interleaved BT m_importer.CurrentImportDomain = ImportDomain.BackTrans; m_importer.ProcessSegment("", @"\id"); // no text provided in segment, just the refs Assert.AreEqual(genesis.Hvo, m_importer.ScrBook.Hvo, "The id line in the BT file should not cause a new ScrBook to get created."); m_importer.TextSegment.FirstReference = new BCVRef(1, 0, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 0, 0); m_importer.ProcessSegment("Title ", @"\mt"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 0); m_importer.ProcessSegment("", @"\c"); m_importer.ProcessSegment("First Section ", @"\s"); m_importer.ProcessSegment("(Lc. 3.23-38)", @"\r"); m_importer.ProcessSegment("", @"\p"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 1); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 1); m_importer.ProcessSegment("First verse ", @"\v"); // ************** finalize ************** m_importer.FinalizeImport(); Assert.AreEqual(1, genesis.SectionsOS.Count); // minor sanity check Assert.AreEqual(1, genesis.TitleOA.ParagraphsOS.Count); IStTxtPara titlePara = (IStTxtPara)genesis.TitleOA.ParagraphsOS[0]; Assert.AreEqual(1, titlePara.TranslationsOC.Count); ICmTranslation titleTranslation = new CmTranslation(Cache, titlePara.TranslationsOC.HvoArray[0]); Assert.AreEqual("Title", titleTranslation.Translation.GetAlternative(m_wsAnal).Text); // Check first section IScrSection section = genesis.SectionsOS[0]; Assert.AreEqual(2, section.HeadingOA.ParagraphsOS.Count); IStTxtPara para = (IStTxtPara)section.HeadingOA.ParagraphsOS[0]; Assert.AreEqual("Primera Seccion", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); ICmTranslation translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("First Section", translation.Translation.GetAlternative(m_wsAnal).Text); para = (IStTxtPara)section.HeadingOA.ParagraphsOS[1]; Assert.AreEqual("(Lc. 3.23-38)", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("(Lc. 3.23-38)", translation.Translation.GetAlternative(m_wsAnal).Text); Assert.AreEqual(1, section.ContentOA.ParagraphsOS.Count); para = (IStTxtPara)section.ContentOA.ParagraphsOS[0]; Assert.AreEqual("11Primer versiculo", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("11First verse", translation.Translation.GetAlternative(m_wsAnal).Text); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Prevents IP-only selections from being associated with a verse number run. /// </summary> /// <param name="vwselNew">The new selection.</param> /// <param name="prootb">The root box.</param> /// <param name="updatedSelection"></param> /// ------------------------------------------------------------------------------------ private void PreventIPAssociationWithVerseRun(IVwSelection vwselNew, IVwRootBox prootb, ref bool updatedSelection) { // Need to commit any editing in progress - otherwise attempt to read // paragraph that follows may get stale data. This follows the example in // EditingHelper.SelectionChanged(). Also verify selection is still valid. Commit(vwselNew); if (!vwselNew.IsValid) return; SelectionHelper helper = SelectionHelper.Create(vwselNew, prootb.Site); // Get the tss that the IP is in ITsString tssSelectedScrPara = null; if (helper.LevelInfo.Length > 0) { switch (m_cache.GetClassOfObject(helper.LevelInfo[0].hvo)) { case CmTranslation.kclsidCmTranslation: int hvo = helper.LevelInfo[0].hvo; int btWs = Callbacks.GetWritingSystemForHvo(hvo); CmTranslation trans = new CmTranslation(m_cache, hvo); tssSelectedScrPara = trans.Translation.GetAlternative(btWs).UnderlyingTsString; break; case StTxtPara.kclsidStTxtPara: StTxtPara para = new StTxtPara(m_cache, helper.LevelInfo[0].hvo); tssSelectedScrPara = para.Contents.UnderlyingTsString; break; case CmPicture.kclsidCmPicture: case StFootnote.kclsidStFootnote: default: // Not sure what it is, but it probably doesn't contain verse text... break; } } // Following code includes checking zero-length paragraphs for association with // the VerseNumber style so that empty paras will use the default character style if (tssSelectedScrPara == null) return; // Get the text props and run info of the run the IP is associating with int charPos = helper.IchAnchor; if (helper.AssocPrev && charPos > 0) charPos -= 1; if (charPos > tssSelectedScrPara.Length) // workaround for TE-5561 charPos = tssSelectedScrPara.Length; TsRunInfo tri; ITsTextProps ttp = tssSelectedScrPara.FetchRunInfoAt(charPos, out tri); // These are the boundary conditions that require our intervention // regarding verse numbers. bool fEdgeOfTss = (helper.IchAnchor == 0 || helper.IchAnchor == tssSelectedScrPara.Length); bool fBeginOfRun = (helper.IchAnchor == tri.ichMin); bool fEndOfRun = (helper.IchAnchor == tri.ichLim); if (!fEdgeOfTss && !fBeginOfRun && !fEndOfRun) return; // If the IP is associated with a verse number style run if (ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle) != ScrStyleNames.VerseNumber) return; try { m_selectionUpdateInProcess = true; //set our semaphore // We must disassociate the IP from the verse number style run... // If IP is at beginning or end of paragraph, need to reset selection to // default paragraph chars (null style). if (fEdgeOfTss) { // REVIEW: Should we be re-getting this, or just using the one we have? vwselNew = prootb.Selection; ITsPropsBldr bldr = ttp.GetBldr(); bldr.SetStrPropValue((int) FwTextPropType.ktptNamedStyle, null); vwselNew.SetIpTypingProps(bldr.GetTextProps()); } else { // Else make the selection be associated with the other adjacent run. helper.AssocPrev = fBeginOfRun; helper.SetSelection(true); } updatedSelection = true; } finally { m_selectionUpdateInProcess = false; // reset semaphore } }
public void FindNextBackTrans_SectionHeadToContent_ContentFinished() { CheckDisposed(); IScrSection section = m_book.SectionsOS[1]; ICmTranslation trans = new CmTranslation(Cache, ((StTxtPara)section.ContentOA.ParagraphsOS[0]).TranslationsOC.HvoArray[0]); m_btDraftView.SetTransStatus(trans, BackTranslationStatus.Finished); m_btDraftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, 0, 1, 0); m_btDraftView.CallNextUnfinishedBackTrans(); SelectionHelper helper = m_btDraftView.EditingHelper.CurrentSelection; Assert.AreEqual(0, helper.IchAnchor); Assert.AreEqual(0, m_btDraftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_btDraftView.TeEditingHelper.SectionIndex); Assert.AreEqual(1, m_btDraftView.ParagraphIndex); Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidContent, m_btDraftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsFalse(m_btDraftView.TeEditingHelper.InBookTitle); }
public void TransWithValidAndNullTypes() { CheckDisposed(); AddDataToMatthew(); ScrSection section = (ScrSection)m_book.SectionsOS[1]; ScrTxtPara para = new ScrTxtPara(Cache, section.ContentOA.ParagraphsOS.HvoArray[0]); // Set up a second and third translation. The first one already had the type set. para.TranslationsOC.Add(new CmTranslation()); para.TranslationsOC.Add(new CmTranslation()); Assert.AreEqual(para.TranslationsOC.Count, 3, "We expect to have three translations owned by the paragraph."); CmTranslation testTrans = (CmTranslation)para.GetBT(); Assert.AreEqual(para.TranslationsOC.Count, 1, "We expect to have only one translation owned by the paragraph." + "The back translation without a type should have been deleted."); CmTranslation trans = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual(trans.TypeRA.Guid, new Guid("80a0dddb-8b4b-4454-b872-88adec6f2aba"), "We expect the translation to be of type back translation."); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle a click on the Back Translation Checked menu option /// </summary> /// ------------------------------------------------------------------------------------ protected bool OnBackTranslationChecked(object args) { CmTranslation trans = new CmTranslation(m_fdoCache, TeEditingHelper.CurrentSelection.LevelInfo[0].hvo); SetBackTranslationStatus(trans, BackTranslationStatus.Checked); return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle the mouse up event. /// </summary> /// <param name="e"></param> /// ------------------------------------------------------------------------------------ protected override void OnMouseUp(MouseEventArgs e) { if (e.Button != MouseButtons.Right) { // If the selection is on the status box of a back translation... Rectangle rcSrcRoot; Rectangle rcDstRoot; GetCoordRects(out rcSrcRoot, out rcDstRoot); IVwSelection sel = m_rootb.MakeSelAt(e.X, e.Y, rcSrcRoot, rcDstRoot, false); if (sel != null && sel.SelType == VwSelType.kstPicture) { SelectionHelper selHelper = SelectionHelper.Create(sel, this); SelLevInfo[] info = selHelper.LevelInfo; // (check the tag and confirm that the same translation status box is selected on // mouse down and mouse up) if (info[0].tag == (int)StTxtPara.StTxtParaTags.kflidTranslations && info[0].hvo == m_selectedTransHvo) { // ...toggle the back translation status to the next status. CmTranslation trans = new CmTranslation(m_fdoCache, info[0].hvo); BackTranslationStatus btStatus = GetBackTranslationStatus(trans); switch (btStatus) { case BackTranslationStatus.Unfinished: default: SetBackTranslationStatus(trans, BackTranslationStatus.Finished); break; case BackTranslationStatus.Finished: SetBackTranslationStatus(trans, BackTranslationStatus.Checked); break; case BackTranslationStatus.Checked: SetBackTranslationStatus(trans, BackTranslationStatus.Unfinished); break; } } } base.OnMouseUp(e); return; } ShowContextMenu(new Point(e.X, e.Y)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a new StFootnote owned by the given book created from the given string /// representation (Created from GetTextRepresentation()) /// </summary> /// <param name="owner">The object that owns the sequence of footnotes into which the /// new footnote is to be inserted</param> /// <param name="flid">The field id of the property in which the footnotes are owned /// </param> /// <param name="sTextRepOfFootnote">The given string representation of a footnote /// </param> /// <param name="footnoteIndex">0-based index where the footnote will be inserted</param> /// <param name="footnoteMarkerStyleName">style name for footnote markers</param> /// <returns>An StFootnote with the properties set to the properties in the /// given string representation</returns> /// ------------------------------------------------------------------------------------ public static StFootnote CreateFromStringRep(CmObject owner, int flid, string sTextRepOfFootnote, int footnoteIndex, string footnoteMarkerStyleName) { StFootnote createdFootnote = new StFootnote(owner, flid, footnoteIndex); // create an XML reader to read in the string representation System.IO.StringReader reader = new System.IO.StringReader(sTextRepOfFootnote); XmlDocument doc = new XmlDocument(); try { doc.Load(reader); } catch (XmlException) { throw new ArgumentException("Unrecognized XML format for footnote."); } XmlNodeList tagList = doc.SelectNodes("FN"); foreach (XmlNode bla in tagList[0].ChildNodes) { // Footnote marker if (bla.Name == "M") { ITsPropsBldr propBlr = TsPropsBldrClass.Create(); propBlr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, footnoteMarkerStyleName); ITsStrBldr tss = TsStrBldrClass.Create(); tss.Replace(0, 0, bla.InnerText, propBlr.GetTextProps()); createdFootnote.FootnoteMarker.UnderlyingTsString = tss.GetString(); } // Display footnote marker else if (bla.Name == "ShowMarker") { createdFootnote.DisplayFootnoteMarker = true; } // display footnote scripture reference else if (bla.Name == "ShowReference") { createdFootnote.DisplayFootnoteReference = true; } // start of a paragraph else if (bla.Name == "P") { StTxtPara newPara = new StTxtPara(); createdFootnote.ParagraphsOS.Append(newPara); ITsIncStrBldr paraBldr = TsIncStrBldrClass.Create(); CmTranslation trans = null; //ITsStrBldr paraBldr = TsStrBldrClass.Create(); foreach (XmlNode paraTextNode in bla.ChildNodes) { if (paraTextNode.Name == "PS") { // paragraph style ITsPropsBldr propBldr = TsPropsBldrClass.Create(); if (!String.IsNullOrEmpty(paraTextNode.InnerText)) { propBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, paraTextNode.InnerText); } else { Debug.Fail("Attempting to create a footnote paragraph with no paragraph style specified!"); } newPara.StyleRules = propBldr.GetTextProps(); } else if (paraTextNode.Name == "RUN") { CreateRunFromStringRep(owner, paraBldr, paraTextNode); paraBldr.Append(paraTextNode.InnerText); } else if (paraTextNode.Name == "TRANS") { if (trans == null) { trans = (CmTranslation)newPara.GetOrCreateBT(); } // Determine which writing system where the string run(s) will be added. string iculocale = paraTextNode.Attributes.GetNamedItem("WS").Value; if (iculocale == null || iculocale == string.Empty) { throw new ArgumentException( "Unknown ICU locale encountered: " + iculocale); } int transWS = owner.Cache.LanguageEncodings.GetWsFromIcuLocale(iculocale); Debug.Assert(transWS != 0, "Unable to find ws from ICU Locale"); // Build a TsString from the run(s) description. ITsIncStrBldr strBldr = TsIncStrBldrClass.Create(); foreach (XmlNode transTextNode in paraTextNode.ChildNodes) { if (transTextNode.Name != "RUN") { throw new ArgumentException("Unexpected translation element '" + transTextNode.Name + "' encountered for ws '" + iculocale + "'"); } CreateRunFromStringRep(owner, strBldr, transTextNode); strBldr.Append(transTextNode.InnerText); } trans.Translation.SetAlternative(strBldr.GetString(), transWS); } } newPara.Contents.UnderlyingTsString = paraBldr.GetString(); } } owner.Cache.PropChanged(null, PropChangeType.kpctNotifyAll, owner.Hvo, flid, footnoteIndex, 1, 0); return(createdFootnote); }
public void VerseInMultipleParagraphs_CharStyle() { IScrBook book = (IScrBook)m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Genesis"); IScrSection section1 = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section1.Hvo, "Primera Seccion", ScrStyleNames.SectionHead); StTxtPara para11 = m_scrInMemoryCache.AddParaToMockedSectionContent(section1.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para11, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(para11, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para11, "Primer versiculo", null); StTxtPara para12 = m_scrInMemoryCache.AddParaToMockedSectionContent(section1.Hvo, "List Item1"); m_scrInMemoryCache.AddRunToMockedPara(para12, "2", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para12, "Segunda versiculo", null); StTxtPara para13 = m_scrInMemoryCache.AddParaToMockedSectionContent(section1.Hvo, "List Item2"); m_scrInMemoryCache.AddRunToMockedPara(para13, "Segunda estrofa", null); StTxtPara para14 = m_scrInMemoryCache.AddParaToMockedSectionContent(section1.Hvo, "List Item2"); m_scrInMemoryCache.AddRunToMockedPara(para14, "Dritte Strophe", null); section1.AdjustReferences(); m_importer.Settings.ImportTranslation = false; m_importer.Settings.ImportBackTranslation = true; m_importer.Settings.ImportBookIntros = false; // ************** process a \id segment, test MakeBook() method ********************* m_importer.TextSegment.FirstReference = new BCVRef(1, 0, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 0, 0); // Set up the Scripture m_importer.ProcessSegment("", @"\id"); // no text provided in segment, just the refs m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 0); m_importer.ProcessSegment("", @"\c"); m_importer.ProcessSegment("Primera Seccion ", @"\s"); m_importer.ProcessSegment("", @"\p"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 1); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 1); m_importer.ProcessSegment("", @"\v"); m_importer.ProcessSegment("First verse ", @"\btvt"); m_importer.ProcessSegment("", @"\li1"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 2); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 2); m_importer.ProcessSegment("", @"\v"); m_importer.ProcessSegment("Second verse", @"\btvt"); m_importer.ProcessSegment("", @"\li2"); m_importer.ProcessSegment("Second stanza ", @"\btvt"); m_importer.ProcessSegment("", @"\li2"); m_importer.ProcessSegment("Third stanza", @"\btvt"); // ************** finalize ************** m_importer.FinalizeImport(); IScrBook genesis = m_importer.ScrBook; Assert.AreEqual(1, genesis.SectionsOS.Count); // minor sanity check // Check first section IScrSection section = genesis.SectionsOS[0]; Assert.AreEqual(1, section.HeadingOA.ParagraphsOS.Count); IStTxtPara para = (IStTxtPara)section.HeadingOA.ParagraphsOS[0]; Assert.AreEqual("Primera Seccion", para.Contents.Text); Assert.AreEqual(0, para.TranslationsOC.Count); Assert.AreEqual(4, section.ContentOA.ParagraphsOS.Count); // paragraph 1 para = (IStTxtPara)section.ContentOA.ParagraphsOS[0]; Assert.AreEqual("11Primer versiculo", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); CmTranslation translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("11First verse", translation.Translation.GetAlternative(m_wsAnal).Text); // paragraph 2 para = (IStTxtPara)section.ContentOA.ParagraphsOS[1]; Assert.AreEqual("2Segunda versiculo", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("2Second verse", translation.Translation.GetAlternative(m_wsAnal).Text); // paragraph 3 para = (IStTxtPara)section.ContentOA.ParagraphsOS[2]; Assert.AreEqual("Segunda estrofa", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("Second stanza", translation.Translation.GetAlternative(m_wsAnal).Text); // paragraph 4 para = (IStTxtPara)section.ContentOA.ParagraphsOS[3]; Assert.AreEqual("Dritte Strophe", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("Third stanza", translation.Translation.GetAlternative(m_wsAnal).Text); }
public void BackTranslationNonInterleaved_ParallelPassage_BtOnly() { // Setup book IScrBook genesis = (IScrBook)m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); m_scrInMemoryCache.AddTitleToMockedBook(genesis.Hvo, "Genesis"); IScrSection section1 = m_scrInMemoryCache.AddSectionToMockedBook(genesis.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section1.Hvo, "Primera Seccion", ScrStyleNames.SectionHead); m_scrInMemoryCache.AddSectionHeadParaToSection(section1.Hvo, "(Lc. 3.23-38)", "Parallel Passage Reference"); StTxtPara para11 = m_scrInMemoryCache.AddParaToMockedSectionContent(section1.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(para11, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(para11, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(para11, "Primer versiculo", null); section1.AdjustReferences(); m_importer.Settings.ImportTranslation = false; m_importer.Settings.ImportBackTranslation = true; m_importer.Settings.ImportBookIntros = true; // Set up the vernacular Scripture - this will be ignored m_importer.TextSegment.FirstReference = new BCVRef(1, 0, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 0, 0); m_importer.ProcessSegment("", @"\id"); // no text provided in segment, just the refs m_importer.ProcessSegment("Titulo ", @"\mt"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 0); m_importer.ProcessSegment("", @"\c"); m_importer.ProcessSegment("Primera Seccion ", @"\s"); m_importer.ProcessSegment("(Lc. 3.23-38)", @"\r"); m_importer.ProcessSegment("", @"\p"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 1); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 1); m_importer.ProcessSegment("Primer versiculo ", @"\v"); Assert.AreEqual(1, genesis.SectionsOS.Count); // minor sanity check // Now test ability to import a non-interleaved BT m_importer.CurrentImportDomain = ImportDomain.BackTrans; m_importer.TextSegment.FirstReference = new BCVRef(1, 0, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 0, 0); m_importer.ProcessSegment("", @"\id"); // no text provided in segment, just the refs Assert.AreEqual(genesis.Hvo, m_importer.ScrBook.Hvo, "The id line in the BT file should not cause a new ScrBook to get created."); m_importer.TextSegment.FirstReference = new BCVRef(1, 0, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 0, 0); m_importer.ProcessSegment("Title ", @"\mt"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 0); m_importer.ProcessSegment("", @"\c"); m_importer.ProcessSegment("First Section ", @"\s"); m_importer.ProcessSegment("(Lc. 3.23-38)", @"\r"); m_importer.ProcessSegment("", @"\p"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 1); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 1); m_importer.ProcessSegment("First verse ", @"\v"); // ************** finalize ************** m_importer.FinalizeImport(); Assert.AreEqual(1, genesis.SectionsOS.Count); // minor sanity check Assert.AreEqual(1, genesis.TitleOA.ParagraphsOS.Count); IStTxtPara titlePara = (IStTxtPara)genesis.TitleOA.ParagraphsOS[0]; Assert.AreEqual(1, titlePara.TranslationsOC.Count); ICmTranslation titleTranslation = new CmTranslation(Cache, titlePara.TranslationsOC.HvoArray[0]); Assert.AreEqual("Title", titleTranslation.Translation.GetAlternative(m_wsAnal).Text); // Check first section IScrSection section = genesis.SectionsOS[0]; Assert.AreEqual(2, section.HeadingOA.ParagraphsOS.Count); IStTxtPara para = (IStTxtPara)section.HeadingOA.ParagraphsOS[0]; Assert.AreEqual("Primera Seccion", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); ICmTranslation translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("First Section", translation.Translation.GetAlternative(m_wsAnal).Text); para = (IStTxtPara)section.HeadingOA.ParagraphsOS[1]; Assert.AreEqual("(Lc. 3.23-38)", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("(Lc. 3.23-38)", translation.Translation.GetAlternative(m_wsAnal).Text); Assert.AreEqual(1, section.ContentOA.ParagraphsOS.Count); para = (IStTxtPara)section.ContentOA.ParagraphsOS[0]; Assert.AreEqual("11Primer versiculo", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("11First verse", translation.Translation.GetAlternative(m_wsAnal).Text); }
public void FindPrevBackTrans_SectionHeadToTitle_TitleChecked() { CheckDisposed(); CmTranslation trans = new CmTranslation(Cache, ((StTxtPara)m_book.TitleOA.ParagraphsOS[0]).TranslationsOC.HvoArray[0]); m_btDraftView.SetTransStatus(trans, BackTranslationStatus.Checked); m_btDraftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, 0, 0, 0); m_btDraftView.CallPrevUnfinishedBackTrans(); SelectionHelper helper = m_btDraftView.EditingHelper.CurrentSelection; Assert.AreEqual(0, helper.IchAnchor); Assert.AreEqual(0, m_btDraftView.TeEditingHelper.BookIndex); Assert.AreEqual(0, m_btDraftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_btDraftView.ParagraphIndex); Assert.IsFalse(m_btDraftView.TeEditingHelper.InBookTitle); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Check the given translation to see if the text is empty. If so, then insert a /// user prompt. /// </summary> /// <param name="vwenv">view environment</param> /// <param name="hvo">id of translation to be displayed</param> /// <returns>true if an empty string was substituted for missing/empty StText</returns> /// ------------------------------------------------------------------------------------ protected override bool InsertTranslationUserPrompt(IVwEnv vwenv, int hvo) { // No user prompt in any of these conditions if (hvo == 0 || Cache.GetClassOfObject(hvo) != (int)CmTranslation.kClassId || m_updatedPrompts.Contains(hvo)) // user interaction has updated prompt { return false; } // If there is text in the translation then do not add a prompt. CmTranslation trans = new CmTranslation(Cache, hvo); if (trans.Translation.GetAlternative(m_wsDefault).Text != null) return false; // If there is no text in the parent paragraph then do not place a prompt in the // back translation. StTxtPara parentPara = new StTxtPara(Cache, trans.OwnerHVO); if (parentPara.Contents.Text == null) return false; // Insert the prompt. vwenv.NoteDependency(new int[] { hvo }, new int[] { (int)CmTranslation.CmTranslationTags.kflidTranslation}, 1); vwenv.AddProp(SimpleRootSite.kTagUserPrompt, this, (int)CmTranslation.CmTranslationTags.kflidTranslation); return true; }
public void FindPrevBackTrans_SectionContentsToSectionHead_HeadFinished() { CheckDisposed(); IScrSection section = m_book.SectionsOS[0]; ICmTranslation trans = new CmTranslation(Cache, ((StTxtPara)section.HeadingOA.ParagraphsOS[0]).TranslationsOC.HvoArray[0]); m_btDraftView.SetTransStatus(trans, BackTranslationStatus.Finished); m_btDraftView.SetInsertionPoint(0, 0, 0, 0, false); m_btDraftView.CallPrevUnfinishedBackTrans(); SelectionHelper helper = m_btDraftView.EditingHelper.CurrentSelection; Assert.AreEqual(0, helper.IchAnchor); Assert.AreEqual(0, m_btDraftView.TeEditingHelper.BookIndex); Assert.AreEqual(-1, m_btDraftView.TeEditingHelper.SectionIndex); Assert.IsTrue(m_btDraftView.TeEditingHelper.InBookTitle); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Replace the user prompt with the text the user typed. This method is called from /// the views code when the user prompt is edited. /// </summary> /// <param name="vwsel">Current selection in rootbox where this prop was updated</param> /// <param name="hvo">Hvo of the paragraph</param> /// <param name="tag">Tag</param> /// <param name="frag">Fragment</param> /// <param name="tssVal">Text the user just typed</param> /// <returns>possibly modified ITsString.</returns> /// <remarks>The return value is currently ignored in production code, but we use it /// in our tests.</remarks> /// ----------------------------------------------------------------------------------- public override ITsString UpdateProp(IVwSelection vwsel, int hvo, int tag, int frag, ITsString tssVal) { CheckDisposed(); Debug.Assert(tag == SimpleRootSite.kTagUserPrompt, "Got an unexpected tag"); Debug.Assert(vwsel != null, "Got a null selection!"); Debug.Assert(vwsel.IsValid, "Got an invalid selection!"); IVwRootBox rootbox = vwsel.RootBox; // If a (typically Chinese) character composition is in progress, replacing the prompt will // destroy the selection and end the composition, causing weird typing problems (TE-8267). // Ending the composition does another Commit, which ensures that this will eventually be // called when there is NOT a composition in progress. if (rootbox.IsCompositionInProgress) return tssVal; // Remove the UserPrompt pseudo-property from the text the user typed. // when appropriate also ensure the correct writing system. // The correct WS is m_wsDefault in the view constructor ITsStrBldr bldr = (ITsStrBldr)tssVal.GetBldr(); if (frag != (int)CmAnnotation.CmAnnotationTags.kflidComment) { bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_wsDefault); } // Delete the user prompt property from the string (TE-3994) bldr.SetIntPropValues(0, bldr.Length, SimpleRootSite.ktptUserPrompt, -1, -1); tssVal = bldr.GetString(); // Get information about current selection int cvsli = vwsel.CLevels(false); cvsli--; // CLevels includes the string property itself, but AllTextSelInfo doesn't need it. int ihvoRoot; int tagTextProp; int cpropPrevious; int ichAnchor; int ichEnd; int ihvoEnd; bool fAssocPrev; int ws; ITsTextProps ttp; SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(vwsel, cvsli, out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev, out ihvoEnd, out ttp); // Prior to the Commit in selection changed which causes this UpdateProp to be called, // earlier selection changed code has expanded the selection (because it is in a user prompt) // to the whole prompt. It is therefore a range selection, and the value of fAssocPrev we got // is useless. We want to make a selection associated with the previous character at the END of // the range. if (frag == (int)CmAnnotation.CmAnnotationTags.kflidComment) { // If the length is zero...we need to suppress replacing the comment with a prompt. if (tssVal.Length == 0) m_hvoSuppressCommentPrompt = hvo; CmIndirectAnnotation ann = new CmIndirectAnnotation(Cache, hvo); if (ann.Comment.GetAlternative(BackTranslationWS).Length == 0) { // Undo needs to unset suppressing the comment prompt. Cache.ActionHandlerAccessor.AddAction(new UndoSuppressCommentPrompt(this, ann)); } // Turn the prompt property off for future typing, too. ITsPropsBldr pb = ttp.GetBldr(); pb.SetIntPropValues(SimpleRootSite.ktptUserPrompt, -1, -1); ann.Comment.SetAlternative(tssVal, BackTranslationWS); rootbox.MakeTextSelection(ihvoRoot, cvsli, rgvsli, (int)CmAnnotation.CmAnnotationTags.kflidComment, cpropPrevious, ichEnd, ichEnd, BackTranslationWS, fAssocPrev, ihvoEnd, pb.GetTextProps(), true); return tssVal; } ReplacePromptUndoAction undoAction = new ReplacePromptUndoAction(hvo, m_cache, m_updatedPrompts); if (m_cache.ActionHandlerAccessor != null) m_cache.ActionHandlerAccessor.AddAction(undoAction); // Mark the user prompt as having been updated - will not show prompt again. // Note: ReplacePromptUndoAction:Undo removes items from the Set. m_updatedPrompts.Add(hvo); // Replace the ITsString in the paragraph or translation // - this destroys the selection because we replace the user prompt. StTxtPara para; CmTranslation trans; ITsTextProps props = StyleUtils.CharStyleTextProps(null, m_wsDefault); if (frag == (int)CmTranslation.CmTranslationTags.kflidTranslation) { trans = new CmTranslation(Cache, hvo); trans.Translation.GetAlternative(m_wsDefault).UnderlyingTsString = tssVal; undoAction.ParaHvo = trans.OwnerHVO; // now set the selection to the end of the text that was just put in. ichAnchor = ichEnd; rootbox.MakeTextSelection(ihvoRoot, cvsli, rgvsli, (int)CmTranslation.CmTranslationTags.kflidTranslation, cpropPrevious, ichAnchor, ichEnd, m_wsDefault, true, ihvoEnd, props, true); } else { para = new StTxtPara(Cache, hvo); para.Contents.UnderlyingTsString = tssVal; undoAction.ParaHvo = hvo; // now set the selection to the end of the text that was just put in. ichAnchor = ichEnd; rootbox.MakeTextSelection(ihvoRoot, cvsli, rgvsli, (int)StTxtPara.StTxtParaTags.kflidContents, cpropPrevious, ichAnchor, ichEnd, m_wsDefault, true, ihvoEnd, props, true); } return tssVal; }
public void FindNextBackTrans_SectionContentToHead_HeadFinished() { CheckDisposed(); // Mark the first section head paragraph BT as finished and add a second section // head paragraph IScrSection section2 = m_book.SectionsOS[1]; StTxtPara para = (StTxtPara)section2.HeadingOA.ParagraphsOS[0]; ICmTranslation trans = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); m_btDraftView.SetTransStatus(trans, BackTranslationStatus.Finished); para = m_scrInMemoryCache.AddSectionHeadParaToSection(section2.Hvo, "Heading 2B", ScrStyleNames.SectionHead); m_inMemoryCache.AddBtToMockedParagraph(para, Cache.DefaultAnalWs); m_btDraftView.RefreshDisplay(); m_btDraftView.SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidContent, 0, 0, 0); m_btDraftView.CallNextUnfinishedBackTrans(); SelectionHelper helper = m_btDraftView.EditingHelper.CurrentSelection; Assert.AreEqual(0, helper.IchAnchor); Assert.AreEqual(0, m_btDraftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_btDraftView.TeEditingHelper.SectionIndex); Assert.AreEqual(1, m_btDraftView.ParagraphIndex); Assert.AreEqual((int)ScrSection.ScrSectionTags.kflidHeading, m_btDraftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsFalse(m_btDraftView.TeEditingHelper.InBookTitle); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add an empty translation of the specified type to the paragraph, or return the /// existing one. /// </summary> /// <param name="owner">the owning paragraph</param> /// <param name="transType">The type of translation to create</param> /// <param name="wsTrans">The writing system of the translation</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public ICmTranslation AddTransToMockedParagraph(StTxtPara owner, Guid transType, int wsTrans) { CheckDisposed(); ICmTranslation trans = owner.GetTrans(transType); if (trans == null) { int hvo = m_cacheBase.NewHvo(CmTranslation.kClassId); m_cacheBase.AppendToFdoVector(owner.Hvo, (int)StTxtPara.StTxtParaTags.kflidTranslations, hvo); m_cacheBase.SetBasicProps(hvo, owner.Hvo, (int)CmTranslation.kClassId, (int)StTxtPara.StTxtParaTags.kflidTranslations, 1); trans = new CmTranslation(Cache, hvo); trans.TypeRA = m_lp.TranslationTagsOA.LookupPossibilityByGuid(transType); } trans.Translation.GetAlternative(wsTrans).Text = string.Empty; return trans; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares the translations of the footnote. /// </summary> /// <param name="expectedTrans">The expected translation</param> /// <param name="actualTrans">The actual translation</param> /// <param name="currentParaHvo">The current footnote paragraph hvo.</param> /// ------------------------------------------------------------------------------------ private void CompareFootnoteTrans(CmTranslation expectedTrans, CmTranslation actualTrans, int currentParaHvo) { if (expectedTrans == null) { Assert.IsNull(actualTrans, "Found an unexpected translation for paragraph hvo " + currentParaHvo); return; } Assert.IsNotNull(actualTrans, "Translation missing for paragraph hvo " + currentParaHvo); // The list of translation writing systems will be set to all the possible // writing systems with the InMemoryCache version of GetUsedScriptureTransWsForPara. List<int> transWs = m_inMemoryCache.Cache.GetUsedScriptureTransWsForPara(currentParaHvo); foreach (int ws in transWs) { ITsString tssExpected = expectedTrans.Translation.GetAlternativeTss(ws); ITsString tssActual = actualTrans.Translation.GetAlternativeTss(ws); if (tssExpected == null || tssExpected.Length == 0) { Assert.IsTrue(tssActual == null || tssActual.Length == 0, "Found an unexpected translation for WS " + ws); continue; } AssertEx.AreTsStringsEqual(tssExpected, tssActual); } }
public void BackTranslationNonInterleaved_DefaultParaCharsStart() { CheckDisposed(); ((ScrImportSet)m_importer.Settings).SetMapping(MappingSet.Main, new ImportMappingInfo(@"\nt", MarkerDomain.Default, "Default Paragraph Characters", null, null)); m_importer.Initialize(); m_importer.Settings.ImportTranslation = true; m_importer.Settings.ImportBackTranslation = true; // ************** process a \id segment, test MakeBook() method ********************* m_importer.TextSegment.FirstReference = new BCVRef(1, 0, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 0, 0); // Set up the vernacular Scripture m_importer.ProcessSegment("", @"\id"); // no text provided in segment, just the refs m_importer.ProcessSegment("Titulo ", @"\mt"); m_importer.ProcessSegment("Primera Seccion ", @"\s"); m_importer.ProcessSegment("", @"\p"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 0); m_importer.ProcessSegment("", @"\c"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 1); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 1); m_importer.ProcessSegment("Primer versiculo ", @"\v"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 2); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 2); m_importer.ProcessSegment("Segundo versiculo ", @"\v"); IScrBook genesis = m_importer.ScrBook; Assert.AreEqual(1, genesis.SectionsOS.Count); // minor sanity check // Now test ability to import a non-interleaved BT m_importer.CurrentImportDomain = ImportDomain.BackTrans; m_importer.ProcessSegment("", @"\id"); // no text provided in segment, just the refs Assert.AreEqual(genesis.Hvo, m_importer.ScrBook.Hvo, "The id line in the BT file should not cause a new ScrBook to get created."); m_importer.TextSegment.FirstReference = new BCVRef(1, 0, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 0, 0); m_importer.ProcessSegment("This is default paragraph characters ", @"\nt"); m_importer.ProcessSegment("Title ", @"\mt"); m_importer.ProcessSegment("First Section ", @"\s"); m_importer.ProcessSegment("", @"\p"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 0); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 0); m_importer.ProcessSegment("", @"\c"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 1); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 1); m_importer.ProcessSegment("First verse ", @"\v"); m_importer.TextSegment.FirstReference = new BCVRef(1, 1, 2); m_importer.TextSegment.LastReference = new BCVRef(1, 1, 2); m_importer.ProcessSegment("Second verse ", @"\v"); // ************** finalize ************** m_importer.FinalizeImport(); Assert.AreEqual(1, genesis.SectionsOS.Count); // minor sanity check Assert.AreEqual(1, genesis.TitleOA.ParagraphsOS.Count); IStTxtPara titlePara = (IStTxtPara)genesis.TitleOA.ParagraphsOS[0]; Assert.AreEqual(1, titlePara.TranslationsOC.Count); ICmTranslation titleTranslation = new CmTranslation(Cache, titlePara.TranslationsOC.HvoArray[0]); Assert.AreEqual("Title", titleTranslation.Translation.GetAlternative(m_wsAnal).Text); // Check first section IScrSection section = genesis.SectionsOS[0]; Assert.AreEqual(1, section.HeadingOA.ParagraphsOS.Count); IStTxtPara para = (IStTxtPara)section.HeadingOA.ParagraphsOS[0]; Assert.AreEqual("Primera Seccion", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); ICmTranslation translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("First Section", translation.Translation.GetAlternative(m_wsAnal).Text); Assert.AreEqual(1, section.ContentOA.ParagraphsOS.Count); para = (IStTxtPara)section.ContentOA.ParagraphsOS[0]; Assert.AreEqual("11Primer versiculo 2Segundo versiculo", para.Contents.Text); Assert.AreEqual(1, para.TranslationsOC.Count); translation = new CmTranslation(Cache, para.TranslationsOC.HvoArray[0]); Assert.AreEqual("11First verse 2Second verse", translation.Translation.GetAlternative(m_wsAnal).Text); }