/// ------------------------------------------------------------------------------------ /// <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(IStTxtPara footnotePara) { ICmTranslation trans = footnotePara.GetBT(); if (trans == null) { return(string.Empty); } StringBuilder transRepresentation = new StringBuilder(); foreach (var ws in trans.AvailableWritingSystems) { ITsString tss = trans.Translation.get_String(ws.Handle); if (tss != null && tss.Length > 0) { transRepresentation.Append("<TRANS WS='"); transRepresentation.Append(ws.Id); transRepresentation.Append("'>"); transRepresentation.Append(GetTextRepresentationOfTsString(tss)); transRepresentation.Append("</TRANS>"); } } return(transRepresentation.ToString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add an empty back translation to the paragraph, or return the existing one. /// </summary> /// <param name="owner">the owning paragraph</param> /// <param name="wsTrans"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected ICmTranslation AddBtToMockedParagraph(IStTxtPara owner, int wsTrans) { ICmTranslation trans = owner.GetOrCreateBT(); trans.Translation.set_String(wsTrans, Cache.TsStrFactory.MakeString(string.Empty, wsTrans)); return(trans); }
/// ------------------------------------------------------------------------------------ /// <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="trans">translation to be displayed</param> /// <returns>true if an empty string was substituted for missing/empty StText</returns> /// ------------------------------------------------------------------------------------ protected override bool InsertTranslationUserPrompt(IVwEnv vwenv, ICmTranslation trans) { // No user prompt in any of these conditions if (trans == null || m_updatedPrompts.Contains(trans.Hvo)) // user interaction has updated prompt { return(false); } // If there is text in the translation then do not add a prompt. if (trans.Translation.get_String(m_wsDefault).Length > 0) { return(false); } // If there is no text in the parent paragraph then do not place a prompt in the // back translation. if (((IStTxtPara)trans.Owner).Contents.Length == 0) { return(false); } // Insert the prompt. vwenv.NoteDependency(new int[] { trans.Hvo }, new int[] { CmTranslationTags.kflidTranslation }, 1); vwenv.AddProp(SimpleRootSite.kTagUserPrompt, this, (int)CmTranslationTags.kflidTranslation); return(true); }
public void NoUserPromptForBTWithEmptyPara() { CheckDisposed(); // Set up a section and empty paragraph IScrSection section = m_inMemoryCache.AddSectionToMockedBook(m_book.Hvo); StTxtPara para = m_inMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); section.AdjustReferences(); // Add an empty translation to the paragraph int wsBT = m_inMemoryCache.Cache.DefaultAnalWs; ICmTranslation trans = m_inMemoryCache.AddBtToMockedParagraph(para, wsBT); m_inMemoryCache.AddRunToMockedTrans(trans, wsBT, string.Empty, null); DummyTeStVc stVc = new DummyTeStVc(m_inMemoryCache.Cache, m_inMemoryCache.Cache.DefaultAnalWs); m_vwenvMock.ExpectNoCall("NoteDependency", new string[] { typeof(int[]).FullName, typeof(int[]).FullName, typeInt }); m_vwenvMock.ExpectNoCall("AddProp", new string[] { typeInt, typeof(IVwViewConstructor).FullName, typeInt }); // verify that the prompt does not get added IVwEnv vwEnv = (IVwEnv)m_vwenvMock.MockInstance; bool fTextAdded = stVc.CallInsertBackTranslationUserPrompt(vwEnv, trans.Hvo); Assert.IsFalse(fTextAdded, "User prompt was added and should not have been"); // verify the mock m_vwenvMock.Verify(); }
public void TemplateCreatedForCurLang() { int germanBtWs = Cache.ServiceLocator.WritingSystemManager.GetWsFromStr("de"); CreatePartialExodusBT(germanBtWs); m_draftView.ViewConstructorWS = germanBtWs; m_draftView.RefreshDisplay(); m_draftView.SetInsertionPoint(0, 1, 0, 0, true); // Generate the section template m_draftView.TeEditingHelper.GenerateTranslationCVNumsForSection(); IStTxtPara para = m_exodus.SectionsOS[1].ContentOA[0]; ICmTranslation transPara1 = para.GetBT(); para = m_exodus.SectionsOS[1].ContentOA[1]; ICmTranslation transPara2 = para.GetBT(); para = m_exodus.SectionsOS[1].ContentOA[2]; ICmTranslation transPara3 = para.GetBT(); Assert.AreEqual("11BT Verse one.", transPara1.Translation.get_String(germanBtWs).Text); Assert.AreEqual("3", transPara2.Translation.get_String(germanBtWs).Text); Assert.AreEqual("4 5", transPara3.Translation.get_String(germanBtWs).Text); }
public void GetAnnotationLocationInfo_BTLongerThanVern() { int wsBt = Cache.DefaultAnalWs; // Add a section IScrSection section = m_scr.ScriptureBooksOS[0].SectionsOS[1]; IStTxtPara para = section.ContentOA[0]; ICmTranslation transPara1 = para.GetOrCreateBT(); // The text "11BT Verse one" is already added, but we add a couple more verses... AddRunToMockedTrans(transPara1, wsBt, " ", null); AddRunToMockedTrans(transPara1, wsBt, "2", ScrStyleNames.VerseNumber); AddRunToMockedTrans(transPara1, wsBt, "BT verse two. ", null); m_draftView.RefreshDisplay(); // Set up a simple selection in the first back translation paragraph. m_draftView.SelectRangeOfChars(0, 1, 0, 0, 25); ICmObject topObj, bottomObj; int wsSelector; int startOffset, endOffset; ITsString tssQuote; BCVRef startRef, endRef; m_draftView.TeEditingHelper.GetAnnotationLocationInfo(out topObj, out bottomObj, out wsSelector, out startOffset, out endOffset, out tssQuote, out startRef, out endRef); Assert.AreEqual(transPara1, topObj); Assert.AreEqual(transPara1, bottomObj); Assert.AreEqual(wsBt, wsSelector); Assert.AreEqual(0, startOffset); Assert.AreEqual(25, endOffset); Assert.AreEqual(new BCVRef(2, 1, 1), startRef); Assert.AreEqual(new BCVRef(2, 1, 2), endRef); Assert.AreEqual("BT Verse one. BT verse", tssQuote.Text); }
public void MarkBtAsUnfinishedOnBtEdit() { // add scripture section and paragraph IScrSection section = AddSectionToMockedBook(m_book); IScrTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.IntroParagraph); AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(para, "This is the verse.", null); // Create a back translation paragraph. int wsBT = Cache.DefaultAnalWs; ICmTranslation btpara = AddBtToMockedParagraph(para, wsBT); AddRunToMockedTrans(btpara, wsBT, "My Back Translation", null); // set the state of the back translation to "checked". btpara.Status.SetAnalysisDefaultWritingSystem(BackTranslationStatus.Checked.ToString()); // change the back translation paragraph btpara.Translation.SetAnalysisDefaultWritingSystem("Your Back Translation"); // make sure the back translation is changed to "unfinished". Assert.AreEqual(BackTranslationStatus.Unfinished.ToString(), btpara.Status.AnalysisDefaultWritingSystem.Text); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add an empty back translation to the paragraph, or return the existing one. /// </summary> /// <param name="owner">the owning paragraph</param> /// <param name="wsTrans"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected ICmTranslation AddBtToMockedParagraph(IStTxtPara owner, int wsTrans) { ICmTranslation trans = owner.GetOrCreateBT(); trans.Translation.set_String(wsTrans, TsStringUtils.EmptyString(wsTrans)); return(trans); }
public override void Initialize() { CheckDisposed(); base.Initialize(); //m_inMemoryCache.InitializeAnnotationDefs(); InstallVirtuals(@"Language Explorer\Configuration\Words\AreaConfiguration.xml", new string[] { "SIL.FieldWorks.IText.ParagraphSegmentsVirtualHandler", "SIL.FieldWorks.IText.OccurrencesInTextsVirtualHandler" }); m_wsVern = Cache.DefaultVernWs; m_wsTrans = Cache.DefaultAnalWs; m_text = new Text(); Cache.LangProject.TextsOC.Add(m_text); m_para = new StTxtPara(); StText text = new StText(); m_text.ContentsOA = text; text.ParagraphsOS.Append(m_para); m_trans = new CmTranslation(); m_para.TranslationsOC.Add(m_trans); kflidFT = StTxtPara.SegmentFreeTranslationFlid(Cache); kflidSegments = StTxtPara.SegmentsFlid(Cache); m_btPoss = Cache.LangProject.TranslationTagsOA.LookupPossibilityByGuid( LangProject.kguidTranBackTranslation); m_trans.TypeRA = m_btPoss; m_fWasUseScriptDigits = Cache.LangProject.TranslatedScriptureOA.UseScriptDigits; Cache.LangProject.TranslatedScriptureOA.UseScriptDigits = false; // do we need to set status? }
public void FindNextBackTrans_SectionContentToHead_HeadFinished() { // Mark the first section head paragraph BT as finished and add a second section // head paragraph IScrSection section2 = m_exodus.SectionsOS[1]; IStTxtPara para = section2.HeadingOA[0]; ICmTranslation trans = para.GetOrCreateBT(); m_draftView.SetTransStatus(trans, BackTranslationStatus.Finished); para = AddSectionHeadParaToSection(section2, "Heading 2B", ScrStyleNames.SectionHead); AddBtToMockedParagraph(para, Cache.DefaultAnalWs); m_draftView.RefreshDisplay(); m_draftView.SetInsertionPoint(ScrSectionTags.kflidContent, 0, 0, 0); m_draftView.CallNextUnfinishedBackTrans(); SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(0, helper.IchAnchor); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(1, m_draftView.ParagraphIndex); Assert.AreEqual(ScrSectionTags.kflidHeading, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsFalse(m_draftView.TeEditingHelper.InBookTitle); }
public void FindPrevBackTrans_SecondBookTitleToFirstBook_LastParaFinished() { // add new book with a BT IScrBook book = AddBookToMockedScripture(3, "Leviticus"); IStText text = AddTitleToMockedBook(book, "Title for Leviticus"); AddBtToMockedParagraph(text[0], Cache.DefaultAnalWs); // add BT for the last section heading of the first book IScrTxtPara para = (IScrTxtPara)m_exodus.SectionsOS[2].HeadingOA[0]; AddBtToMockedParagraph(para, Cache.DefaultAnalWs); // add BT for last para of first book para = (IScrTxtPara)m_exodus.SectionsOS[2].ContentOA[0]; ICmTranslation trans = AddBtToMockedParagraph(para, Cache.DefaultAnalWs); m_draftView.SetTransStatus(trans, BackTranslationStatus.Finished); m_draftView.RefreshDisplay(); m_draftView.SetInsertionPoint(ScrBookTags.kflidTitle, 1, 0); m_draftView.CallPrevUnfinishedBackTrans(); SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(0, helper.IchAnchor); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(2, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); Assert.AreEqual(ScrSectionTags.kflidHeading, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsFalse(m_draftView.TeEditingHelper.InBookTitle); }
public void FindNextMissingBtFootnoteMarker_BtSectionHeadToContent() { IScrSection section = m_exodus.SectionsOS[1]; ITsStrFactory strfact = TsStrFactoryClass.Create(); IStTxtPara contentPara = section.ContentOA[0]; ITsStrBldr strBldr = contentPara.Contents.GetBldr(); IStFootnote foot = m_exodus.InsertFootnoteAt(0, strBldr, 7); contentPara.Contents = strBldr.GetString(); IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( foot, ScrStyleNames.NormalFootnoteParagraph); footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs); ICmTranslation trans = contentPara.GetOrCreateBT(); m_draftView.SetInsertionPoint(ScrSectionTags.kflidHeading, 0, 1, 0); m_draftView.CallNextMissingBtFootnoteMarker(); SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(2, helper.IchAnchor, "IP should be after chapter and verse number."); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); Assert.AreEqual(ScrSectionTags.kflidContent, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation); }
public void FindNextMissingBtFootnoteMarker_BtSectionHeadToNowhere() { IScrSection section = m_exodus.SectionsOS[1]; ITsStrFactory strfact = TsStrFactoryClass.Create(); IStTxtPara contentPara = section.ContentOA[0]; ITsStrBldr strBldr = contentPara.Contents.GetBldr(); IStFootnote foot = m_exodus.InsertFootnoteAt(0, strBldr, 7); contentPara.Contents = strBldr.GetString(); IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( foot, ScrStyleNames.NormalFootnoteParagraph); footPara.Contents = strfact.MakeString("This is footnote text for footnote", Cache.DefaultVernWs); ICmTranslation trans = contentPara.GetOrCreateBT(); ITsStrBldr bldr = trans.Translation.get_String(Cache.DefaultAnalWs).GetBldr(); TsStringUtils.InsertOrcIntoPara(foot.Guid, FwObjDataTypes.kodtNameGuidHot, bldr, 2, 2, Cache.DefaultAnalWs); trans.Translation.set_String(Cache.DefaultAnalWs, bldr.GetString()); m_draftView.SetInsertionPoint(ScrSectionTags.kflidHeading, 0, 1, 0); m_draftView.CallNextMissingBtFootnoteMarker(); SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection; Assert.AreEqual(0, helper.IchAnchor); Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex); Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex); Assert.AreEqual(0, m_draftView.ParagraphIndex); Assert.AreEqual(ScrSectionTags.kflidHeading, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag); Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation); }
public void MarkBtAsUnfinishedOnVernacularEdit() { // add scripture section and paragraph IScrSection section = AddSectionToMockedBook(m_book); IScrTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.IntroParagraph); AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(para, "This is the verse.", null); // Create a back translation paragraph. int wsBT = Cache.DefaultAnalWs; ICmTranslation btpara = AddBtToMockedParagraph(para, wsBT); AddRunToMockedTrans(btpara, wsBT, "My Back Translation", null); // set the state of the back translation to "finished". btpara.Status.SetAnalysisDefaultWritingSystem(BackTranslationStatus.Finished.ToString()); // change the vernacular paragraph ITsStrBldr strBuilder = para.Contents.GetBldr(); strBuilder.ReplaceRgch(0, 1, "5", 1, para.Contents.get_Properties(0)); para.Contents = strBuilder.GetString(); // make sure the back translation is changed to "unfinished". string checkState = BackTranslationStatus.Unfinished.ToString(); Assert.AreEqual(checkState, btpara.Status.AnalysisDefaultWritingSystem.Text); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the section index and paragraph index for the specified object, either an /// StTxtPara or a ICmTranslation/ISegment of an IScrTxtPara. /// </summary> /// <param name="obj">An ICmObject associated with an annotation (i.e. the annotation's /// BeginObjectRA) If this is not a IScrTxtPara or ICmTranslation/ISegment of a IScrTxtPara, this /// method can't do anything very useful.</param> /// <param name="iNewNoteSection">The index of the section, or -1 if the index cannot /// be determined.</param> /// <param name="iNewNotePara">The index of paragraph, or int.MaxValue if the index /// cannot be determined.</param> /// ------------------------------------------------------------------------------------ private void GetLocationInfoForObj(ICmObject obj, out int iNewNoteSection, out int iNewNotePara) { iNewNoteSection = -1; iNewNotePara = int.MaxValue; // Don't rely on secion/paragraph information if reference object is in a saved version if (obj == null || obj.OwnerOfClass <IScrDraft>() != null) { return; } if (obj is IScrTxtPara) { IScrTxtPara para = (IScrTxtPara)obj; iNewNotePara = para.IndexInOwner; IScrSection section = para.OwningSection; if (section != null) { iNewNoteSection = section.IndexInOwner; } } else if (obj is ICmTranslation) { ICmTranslation trans = (ICmTranslation)obj; Debug.Assert(trans.Owner is IScrTxtPara); GetLocationInfoForObj(trans.Owner, out iNewNoteSection, out iNewNotePara); } else if (obj is ISegment) { ISegment segment = (ISegment)obj; Debug.Assert(segment.Owner is IScrTxtPara); GetLocationInfoForObj(segment.Owner, out iNewNoteSection, out iNewNotePara); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Compares the translations of the footnote. /// </summary> /// <param name="expectedTrans">The expected translation</param> /// <param name="currentPara">The current footnote paragraph.</param> /// ------------------------------------------------------------------------------------ private void CompareFootnoteTrans(ICmTranslation expectedTrans, IStTxtPara currentPara) { ICmTranslation actualTrans = currentPara.GetBT(); if (expectedTrans == null) { Assert.IsNull(actualTrans, "Found an unexpected translation for footnote paragraph " + currentPara.IndexInOwner + " having text: " + currentPara.Contents.Text); return; } Assert.IsNotNull(actualTrans, "Translation missing for paragraph " + currentPara.IndexInOwner + " having text: " + currentPara.Contents.Text); foreach (int ws in actualTrans.Translation.AvailableWritingSystemIds) { ITsString tssExpected = expectedTrans.Translation.get_String(ws); ITsString tssActual = actualTrans.Translation.get_String(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); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Helper method to set up the test paragraph in m_archivedText, including footnotes /// and back translations, plus any other fields deemed necessary. /// </summary> /// ------------------------------------------------------------------------------------ private StTxtPara SetUpParagraphInArchiveWithFootnotesAndBT() { // Prepare the Revision paragraph in m_archivedText // note: CreateTestData has already placed "11This is the previous version of the text." // in paragraph in m_archivedText. StTxtPara paraRev = (StTxtPara)m_archivedText.ParagraphsOS[0]; paraRev.StyleRules = StyleUtils.ParaStyleTextProps("Line 1"); // add footnotes to existing paragraph. StFootnote footnote1 = m_inMemoryCache.AddFootnote(m_archivedFootnotesOS, paraRev, 6, "Footnote1"); StFootnote footnote2 = m_inMemoryCache.AddFootnote(m_archivedFootnotesOS, paraRev, 10, "Footnote2"); Assert.AreEqual(2, m_archivedFootnotesOS.Count); // Add two back translations of the para and footnotes int[] wsBt = new int[] { InMemoryFdoCache.s_wsHvos.En, InMemoryFdoCache.s_wsHvos.De }; foreach (int ws in wsBt) { // add back translation of the para, and status ICmTranslation paraTrans = m_inMemoryCache.AddBtToMockedParagraph(paraRev, ws); m_inMemoryCache.AddRunToMockedTrans(paraTrans, ws, "BT of test paragraph" + ws.ToString(), null); paraTrans.Status.SetAlternative(BackTranslationStatus.Finished.ToString(), ws); // add BT footnotes, and status ICmTranslation footnoteTrans = m_inMemoryCache.AddFootnoteORCtoTrans(paraTrans, 2, ws, footnote1, "BT of footnote1 " + ws.ToString()); footnoteTrans.Status.SetAlternative(BackTranslationStatus.Checked.ToString(), ws); footnoteTrans = m_inMemoryCache.AddFootnoteORCtoTrans(paraTrans, 6, ws, footnote2, "BT of footnote2 " + ws.ToString()); footnoteTrans.Status.SetAlternative(BackTranslationStatus.Finished.ToString(), ws); } return(paraRev); }
public void DeleteFootnoteMarkerInBt_ContextMenu() { CheckDisposed(); IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(2, "Exodus"); m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Exodus"); m_btDraftView.BookFilter.Insert(0, book.Hvo); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "The first section", ScrStyleNames.SectionHead); // Construct a parent paragraph StTxtPara parentPara = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "uno ", null); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "2", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "dos ", null); StFootnote footnote1 = m_scrInMemoryCache.AddFootnote(book, parentPara, 5); m_scrInMemoryCache.AddParaToMockedText(footnote1.Hvo, ScrStyleNames.NormalFootnoteParagraph); StFootnote footnote2 = m_scrInMemoryCache.AddFootnote(book, parentPara, 10); m_scrInMemoryCache.AddParaToMockedText(footnote2.Hvo, ScrStyleNames.NormalFootnoteParagraph); Guid guid1 = footnote1.Guid; Guid guid2 = footnote2.Guid; Assert.AreEqual(2, book.FootnotesOS.Count); section.AdjustReferences(); // Construct the initial back translation int wsBt = m_inMemoryCache.Cache.DefaultAnalWs; ICmTranslation trans = m_inMemoryCache.AddBtToMockedParagraph(parentPara, wsBt); m_inMemoryCache.AddRunToMockedTrans(trans, wsBt, "one two", null); ITsStrBldr btTssBldr = trans.Translation.GetAlternative(wsBt).UnderlyingTsString.GetBldr(); footnote1.InsertRefORCIntoTrans(btTssBldr, 3, wsBt); footnote2.InsertRefORCIntoTrans(btTssBldr, 8, wsBt); trans.Translation.SetAlternative(btTssBldr.GetString(), wsBt); SelectionHelper selHelper = m_btDraftView.SetInsertionPoint(0, 0, 0, 3, false); //set the IP // Delete the marker for the back translation of the first footnote m_btDraftView.OnDeleteFootnote(); // Verify that both original footnotes still exist and that the first BT footnote marker is // deleted. Assert.AreEqual(2, book.FootnotesOS.Count); VerifyFootnote(footnote1, parentPara, 5); VerifyFootnote(footnote2, parentPara, 10); Assert.AreEqual("one two" + StringUtils.kchObject, trans.Translation.GetAlternative(wsBt).UnderlyingTsString.Text); StTxtParaTests.VerifyBtFootnote(footnote2, parentPara, wsBt, 7); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a run of text to the specified translation /// </summary> /// <param name="trans">The translation where the run of text will be appended.</param> /// <param name="btWS">The writing system of the back translation</param> /// <param name="runWS">The writing system of the run</param> /// <param name="runText">The run text.</param> /// <param name="runStyleName">Name of the run style.</param> /// ------------------------------------------------------------------------------------ protected void AddRunToMockedTrans(ICmTranslation trans, int btWS, int runWS, string runText, string runStyleName) { ITsTextProps runProps = TsStringUtils.MakeProps(runStyleName, runWS); ITsStrBldr bldr = trans.Translation.get_String(btWS).GetBldr(); bldr.Replace(bldr.Length, bldr.Length, runText, runProps); trans.Translation.set_String(btWS, bldr.GetString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a back translation from a format string, and attach it to the /// given paragraph. /// </summary> /// <param name="testBase">in-memory test base</param> /// <param name="book">book to use</param> /// <param name="para">the paragraph that will own this back translation</param> /// <param name="format">(See CreateText for the definition of the format string)</param> /// <param name="ws">writing system of the back translation</param> /// ------------------------------------------------------------------------------------ internal static void AddBackTranslation(ScrInMemoryFdoTestBase testBase, IScrBook book, IScrTxtPara para, string format, int ws) { ICmTranslation cmTrans = para.GetOrCreateBT(); // Set the translation string for the given WS cmTrans.Translation.set_String(ws, testBase.CreateFormatText(book, null, format, ws)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a back translation footnote ref ORC in the given translation for the given footnote /// </summary> /// <param name="trans">The given translation, usually a back translation</param> /// <param name="ichPos">The 0-based character offset into the translation string /// at which we will insert the reference ORC</param> /// <param name="ws">writing system of the ORC</param> /// <param name="footnote">The given footnote</param> /// ------------------------------------------------------------------------------------ public void AddBtFootnote(ICmTranslation trans, int ichPos, int ws, IStFootnote footnote) { // Insert a footnote reference ORC into the given translation string ITsStrBldr tsStrBldr = trans.Translation.get_String(ws).GetBldr(); TsStringUtils.InsertOrcIntoPara(footnote.Guid, FwObjDataTypes.kodtNameGuidHot, tsStrBldr, ichPos, ichPos, ws); trans.Translation.set_String(ws, tsStrBldr.GetString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Clones this instance. /// </summary> /// <param name="clone"></param> /// ------------------------------------------------------------------------------------ public void SetCloneProperties(ICmObject clone) { ICmTranslation clonedTrans = (ICmTranslation)clone; clonedTrans.TypeRA = TypeRA; // Must be set before copying the alternatives clonedTrans.Translation.CopyAlternatives(Translation); clonedTrans.Status.CopyAlternatives(Status); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a footnote reference marker (ref orc) /// </summary> /// <param name="footnote">given footnote</param> /// <param name="para">paragraph owning the translation to insert footnote marker into</param> /// <param name="ws">given writing system for the back translation</param> /// <param name="ichPos">The 0-based character offset into the translation</param> /// ------------------------------------------------------------------------------------ protected void InsertTestBtFootnote(StFootnote footnote, StTxtPara para, int ws, int ichPos) { ICmTranslation trans = para.GetOrCreateBT(); ITsStrBldr bldr = trans.Translation.GetAlternative(ws).UnderlyingTsString.GetBldr(); footnote.InsertRefORCIntoTrans(bldr, ichPos, ws); trans.Translation.SetAlternative(bldr.GetString(), ws); }
public void SkipExtraFootnoteInBT() { // Set up the vernacular to match the BT we will import. IScrBook book = AddBookToMockedScripture(2, "Exodo"); IScrSection sectionMajor = AddSectionToMockedBook(book); AddParaToMockedText(sectionMajor.HeadingOA, "Section Head"); IStTxtPara para = AddParaToMockedSectionContent(sectionMajor, ScrStyleNames.NormalParagraph); AddRunToMockedPara(para, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(para, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(para, "verse one text", null); m_importer.Settings.ImportBackTranslation = true; m_importer.CurrentImportDomain = ImportDomain.BackTrans; m_importer.StreamLinedImport = true; // ************** process a \id segment, test MakeBook() method ********************* m_importer.TextSegment.FirstReference = new BCVRef(2, 0, 0); m_importer.TextSegment.LastReference = new BCVRef(2, 0, 0); m_importer.ProcessSegment("", @"\id"); // no text provided in segment, just the refs Assert.AreEqual(2, m_importer.BookNumber); // verify that we didn't create a different book Assert.AreEqual(book.Hvo, m_importer.ScrBook.Hvo); // begin section (Scripture text) // ************** process a chapter ********************* m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 0); m_importer.TextSegment.LastReference = new BCVRef(2, 1, 0); m_importer.ProcessSegment("", @"\c"); // ************** process a section head (for 1:1) ********************* m_importer.ProcessSegment("First Scripture Section", @"\s"); // ************** process paragraph with unmatched footnote ********************* m_importer.ProcessSegment("", @"\p"); m_importer.TextSegment.FirstReference = new BCVRef(2, 1, 1); m_importer.TextSegment.LastReference = new BCVRef(2, 1, 1); m_importer.ProcessSegment("", @"\v"); m_importer.ProcessSegment("+", @"\f"); m_importer.ProcessSegment("BT for footnote", @"\ft"); m_importer.ProcessSegment("BT text for verse one", @"\vt"); // ************** finalize ************** m_importer.FinalizeImport(); // Check the BT of the content paragraph Assert.AreEqual(1, para.TranslationsOC.Count); ICmTranslation trans1 = para.GetBT(); Assert.IsNotNull(trans1); ITsString tss1 = trans1.Translation.AnalysisDefaultWritingSystem; AssertEx.RunIsCorrect(tss1, 0, "1", ScrStyleNames.ChapterNumber, m_wsAnal); AssertEx.RunIsCorrect(tss1, 1, "1", ScrStyleNames.VerseNumber, m_wsAnal); AssertEx.RunIsCorrect(tss1, 2, "BT text for verse one", null, m_wsAnal); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a back translation from a format string, and attach it to the /// given paragraph. /// </summary> /// <param name="scrInMemoryCache">in-memory cache to use for testing</param> /// <param name="book">book to use</param> /// <param name="para">the paragraph that will own this back translation</param> /// <param name="format">(See CreateText for the definition of the format string)</param> /// <param name="ws">writing system of the back translation</param> /// ------------------------------------------------------------------------------------ internal static void AddBackTranslation(ScrInMemoryFdoCache scrInMemoryCache, IScrBook book, StTxtPara para, string format, int ws) { ICmTranslation cmTrans = para.GetOrCreateBT(); // Set the translation string for the given WS cmTrans.Translation.GetAlternative(ws).UnderlyingTsString = ScrInMemoryFdoCache.CreateFormatText(book, null, format, ws); }
public void DeleteFootnoteMarkerInBt_ContextMenu() { IScrBook book = AddBookToMockedScripture(1, "Genesis"); AddTitleToMockedBook(book, "Genesis"); m_draftView.BookFilter.Add(book); IScrSection section = AddSectionToMockedBook(book); AddSectionHeadParaToSection(section, "The first section", ScrStyleNames.SectionHead); // Construct a parent paragraph IStTxtPara parentPara = AddParaToMockedSectionContent(section, ScrStyleNames.NormalParagraph); AddRunToMockedPara(parentPara, "1", ScrStyleNames.ChapterNumber); AddRunToMockedPara(parentPara, "1", ScrStyleNames.VerseNumber); AddRunToMockedPara(parentPara, "uno ", null); AddRunToMockedPara(parentPara, "2", ScrStyleNames.VerseNumber); AddRunToMockedPara(parentPara, "dos ", null); IStFootnote footnote1 = AddFootnote(book, parentPara, 5); AddParaToMockedText(footnote1, ScrStyleNames.NormalFootnoteParagraph); IStFootnote footnote2 = AddFootnote(book, parentPara, 10); AddParaToMockedText(footnote2, ScrStyleNames.NormalFootnoteParagraph); Assert.AreEqual(2, book.FootnotesOS.Count); // Construct the initial back translation int wsBt = Cache.DefaultAnalWs; ICmTranslation trans = AddBtToMockedParagraph(parentPara, wsBt); AddRunToMockedTrans(trans, wsBt, "one two", null); ITsStrBldr btTssBldr = trans.Translation.get_String(wsBt).GetBldr(); TsStringUtils.InsertOrcIntoPara(footnote1.Guid, FwObjDataTypes.kodtNameGuidHot, btTssBldr, 3, 3, wsBt); TsStringUtils.InsertOrcIntoPara(footnote2.Guid, FwObjDataTypes.kodtNameGuidHot, btTssBldr, 8, 8, wsBt); trans.Translation.set_String(wsBt, btTssBldr.GetString()); m_draftView.RefreshDisplay(); // Delete the marker for the back translation of the first footnote. We have to make a range selection // because by the time the tested method is called, a range selection of any adjacent footnotes has // already been made. SelectionHelper selHelper = m_draftView.SelectRangeOfChars(0, 0, 0, 3, 4); m_draftView.CallDeleteFootnote(); // Verify that both original footnotes still exist and that the first BT footnote marker is // deleted. Assert.AreEqual(2, book.FootnotesOS.Count); VerifyFootnote(footnote1, parentPara, 5); VerifyFootnote(footnote2, parentPara, 10); Assert.AreEqual("one two" + StringUtils.kChObject, trans.Translation.get_String(wsBt).Text); FdoTestHelper.VerifyBtFootnote(footnote2, parentPara, wsBt, 7); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure the marker for a footnote exists in the back translation and refers to the /// footnote properly. /// </summary> /// <param name="footnote">given footnote whose marker we want to verify in the BT</param> /// <param name="para">vernacular paragraph which owns the back translation</param> /// <param name="ws">writing system of the back transltion</param> /// <param name="ich">Character position where ORC should be in the specified back /// translation</param> /// ------------------------------------------------------------------------------------ public static void VerifyBtFootnote(IStFootnote footnote, IStTxtPara para, int ws, int ich) { ICmTranslation trans = para.GetBT(); ITsString btTss = trans.Translation.get_String(ws); int iRun = btTss.get_RunAt(ich); Guid newFootnoteGuid = TsStringUtils.GetGuidFromRun(btTss, iRun, FwObjDataTypes.kodtNameGuidHot); Assert.AreEqual(footnote.Guid, newFootnoteGuid); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Append a run of text to a back translation of a paragraph. /// </summary> /// <param name="para">given paragraph</param> /// <param name="ws">given writing system for the back translation</param> /// <param name="runText">given text to append to back translation</param> /// ------------------------------------------------------------------------------------ public void AppendRunToBt(IStTxtPara para, int ws, string runText) { ICmTranslation trans = para.GetOrCreateBT(); ITsStrBldr bldr = trans.Translation.get_String(ws).GetBldr(); ITsTextProps ttp = StyleUtils.CharStyleTextProps(null, ws); int bldrLength = bldr.Length; bldr.ReplaceRgch(bldrLength, bldrLength, runText, runText.Length, ttp); trans.Translation.set_String(ws, bldr.GetString()); }
public void EnterKey_InBtSectionHead() { CheckDisposed(); IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(2, "Exodus"); m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Exodus"); m_btDraftView.BookFilter.Insert(0, book.Hvo); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); StTxtPara headPara = m_scrInMemoryCache.AddSectionHeadParaToSection( section.Hvo, "The first section", ScrStyleNames.SectionHead); // Construct a parent paragraph StTxtPara parentPara = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "uno ", null); section.AdjustReferences(); // Construct the initial back translation. int wsBt = m_inMemoryCache.Cache.DefaultAnalWs; ICmTranslation headingTrans = m_inMemoryCache.AddBtToMockedParagraph(headPara, wsBt); m_inMemoryCache.AddRunToMockedTrans(headingTrans, wsBt, "BT heading", ScrStyleNames.Header); ICmTranslation paraTrans = m_inMemoryCache.AddBtToMockedParagraph(parentPara, wsBt); m_inMemoryCache.AddRunToMockedTrans(paraTrans, wsBt, "one", null); // Set the following style for section head. IStStyle styleHead = m_scr.FindStyle(ScrStyleNames.SectionHead); IStStyle stylePara = m_scr.FindStyle(ScrStyleNames.NormalParagraph); styleHead.NextRA = stylePara; // Set IP at the end of the section head. int sectionHeadLength = headingTrans.Translation.GetAlternativeTss(wsBt).Length; m_btDraftView.TeEditingHelper.SetInsertionPoint( (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0, 0, sectionHeadLength, false); m_btDraftView.OnKeyPress(new KeyPressEventArgs('\r')); // Verify that the selection has moved to the start of the BT of the section Content. IVwSelection vwsel = m_btDraftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss; vwsel.TextSelInfo(false, out tss, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual((int)CmTranslation.CmTranslationTags.kflidTranslation, textTag); Assert.AreEqual(paraTrans.Hvo, hvo, "Current paragraph should be content following section head."); Assert.AreEqual(0, ich); // selection is at start of paragraph }
public void CreateBtWhenContentParagraphIsAdded() { // add scripture section and paragraph IScrSection section = AddSectionToMockedBook(m_book); IScrTxtPara para = AddParaToMockedSectionContent(section, ScrStyleNames.IntroParagraph); // make sure the back translation is created. ICmTranslation bt = para.GetBT(); Assert.IsNotNull(bt); Assert.IsNull(bt.Status.AnalysisDefaultWritingSystem.Text); }
private void FixtureSetupInternal() { //IWritingSystem wsEn = Cache.WritingSystemFactory.get_Engine("en"); // Setup default analysis ws //m_wsEn = Cache.ServiceLocator.GetInstance<ILgWritingSystemRepository>().GetObject(wsEn.WritingSystem); m_wsVern = Cache.DefaultVernWs; m_wsTrans = Cache.DefaultAnalWs; m_text = Cache.ServiceLocator.GetInstance<ITextFactory>().Create(); //Cache.LangProject.TextsOC.Add(m_text); var stText = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create(); m_text.ContentsOA = stText; m_para = Cache.ServiceLocator.GetInstance<IScrTxtParaFactory>().CreateWithStyle(stText, ScrStyleNames.NormalParagraph); m_trans = m_para.GetOrCreateBT(); Cache.LangProject.TranslatedScriptureOA.UseScriptDigits = false; m_tsf = Cache.TsStrFactory; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Merges the CmTranslations selecting the longest alternative for each of the available /// writing systems. /// </summary> /// <param name="trans">The translation to merge into the existing translation.</param> /// <param name="existingBtTrans">The existing translation.</param> /// ------------------------------------------------------------------------------------ private static void MergeCmTranslations(ICmTranslation trans, ICmTranslation existingBtTrans) { foreach (int wsBt in trans.Translation.AvailableWritingSystemIds) { ITsString tssTrans = trans.Translation.get_String(wsBt); ITsString tssExistingTrans = existingBtTrans.Translation.get_String(wsBt); if (tssTrans.Length > tssExistingTrans.Length) existingBtTrans.Translation.set_String(wsBt, tssTrans); } }
internal BackTranslationInfo(ICmTranslation backtran) { foreach (IWritingSystem ws in backtran.Cache.ServiceLocator.WritingSystems.AnalysisWritingSystems) { ITsString tss = backtran.Translation.get_String(ws.Handle); if (tss.Length > 0 && tss != backtran.Translation.NotFoundTss) m_mapWsTssTran.Add(ws.Handle, tss); string status = backtran.Status.get_String(ws.Handle).Text; if (!String.IsNullOrEmpty(status) && status != backtran.Status.NotFoundTss.Text) m_mapWsTssStatus.Add(ws.Handle, status); } m_hvo = backtran.Hvo; }
private void SetupSelRangeForChapterInsert(int ichInitial, int ichEnd, ICmTranslation trans, int wsBT) { m_selHelper.SetupResult("IchAnchor", ichInitial); m_selHelper.SetupResult("IchEnd", ichEnd); m_selHelper.SetupResult("IsValid", true); ITsString tssTrans = trans.Translation.GetAlternative(wsBT).UnderlyingTsString; m_sel.SetupResult("SelType", VwSelType.kstText); m_sel.SetupResultForParams("TextSelInfo", null, m_TextSelInfoArgs, m_TextSelInfoTypes, new object[] { true, tssTrans, Math.Min(ichInitial, ichEnd), false, trans.Hvo, kflidTrans, wsBT }); m_sel.SetupResultForParams("TextSelInfo", null, new object[] { false, null, null, null, null, null, null }, m_TextSelInfoTypes, new object[] { false, tssTrans, Math.Max(ichInitial, ichEnd), false, trans.Hvo, kflidTrans, wsBT }); m_sel.SetupResult("IsRange", true); m_rootBox.SetupResult("Selection", m_sel.MockInstance); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get the status of a back translation object /// </summary> /// <param name="trans"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private BackTranslationStatus GetBackTranslationStatus(ICmTranslation trans) { Debug.Assert(trans.TypeRA.Guid == LangProjectTags.kguidTranBackTranslation); string status = trans.Status.get_String(ViewConstructorWS).Text; if (status == BackTranslationStatus.Checked.ToString()) return BackTranslationStatus.Checked; if (status == BackTranslationStatus.Finished.ToString()) return BackTranslationStatus.Finished; return BackTranslationStatus.Unfinished; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a run of text to the specified translation /// </summary> /// <param name="trans">The translation where the run of text will be appended.</param> /// <param name="btWS">The writing system of the back translation</param> /// <param name="runWS">The writing system of the run</param> /// <param name="runText">The run text.</param> /// <param name="runStyleName">Name of the run style.</param> /// ------------------------------------------------------------------------------------ protected void AddRunToMockedTrans(ICmTranslation trans, int btWS, int runWS, string runText, string runStyleName) { ITsPropsFactory propFact = TsPropsFactoryClass.Create(); ITsTextProps runProps = propFact.MakeProps(runStyleName, runWS, 0); ITsStrBldr bldr = trans.Translation.get_String(btWS).GetBldr(); bldr.Replace(bldr.Length, bldr.Length, runText, runProps); trans.Translation.set_String(btWS, bldr.GetString()); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a back translation footnote in the given translation for the given footnote. /// Inserts a ref ORC in the translation and sets the the BT text in the footnote. /// </summary> /// <param name="trans">The given back translation of an StTxtPara</param> /// <param name="ichPos">The 0-based character offset into the back translation string /// at which we will insert the reference ORC</param> /// <param name="ws">writing system of the BT and ORC</param> /// <param name="footnote">The given footnote</param> /// <param name="footnoteBtText">text for the back translation of the footnote</param> /// <returns>the back translation of the given footnote</returns> /// ------------------------------------------------------------------------------------ public ICmTranslation AddBtFootnote(ICmTranslation trans, int ichPos, int ws, IStFootnote footnote, string footnoteBtText) { AddBtFootnote(trans, ichPos, ws, footnote); // Add the given footnote BT text to the footnote. IStTxtPara para = (IStTxtPara)footnote.ParagraphsOS[0]; ICmTranslation footnoteTrans = para.GetOrCreateBT(); ITsStrBldr tssFootnoteBldr = footnoteTrans.Translation.get_String(ws).GetBldr(); tssFootnoteBldr.ReplaceRgch(0, 0, footnoteBtText, footnoteBtText.Length, StyleUtils.CharStyleTextProps(null, ws)); footnoteTrans.Translation.set_String(ws, tssFootnoteBldr.GetString()); return footnoteTrans; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a run of text to the specified translation /// </summary> /// <param name="trans"></param> /// <param name="btWS"></param> /// <param name="runText"></param> /// <param name="runStyleName"></param> /// ------------------------------------------------------------------------------------ public void AddRunToMockedTrans(ICmTranslation trans, int btWS, string runText, string runStyleName) { CheckDisposed(); AddRunToMockedTrans(trans, btWS, btWS, runText, runStyleName); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a run of text to the specified translation /// </summary> /// <param name="trans">The translation where the run of text will be appended.</param> /// <param name="btWS">The writing system of the back translation</param> /// <param name="runWS">The writing system of the run</param> /// <param name="runText">The run text.</param> /// <param name="runStyleName">Name of the run style.</param> /// ------------------------------------------------------------------------------------ public void AddRunToMockedTrans(ICmTranslation trans, int btWS, int runWS, string runText, string runStyleName) { CheckDisposed(); ITsPropsFactory propFact = TsPropsFactoryClass.Create(); ITsTextProps runProps = propFact.MakeProps(runStyleName, runWS, 0); TsStringAccessor contents = trans.Translation.GetAlternative(btWS); ITsStrBldr bldr = contents.UnderlyingTsString.GetBldr(); bldr.Replace(bldr.Length, bldr.Length, runText, runProps); contents.UnderlyingTsString = bldr.GetString(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Parse individual verse information for the given back translation. /// This generates an array with an element for each desired writing system. /// Each element is a List of ChapterVerseInfo objects. /// </summary> /// <param name="cmTrans">the back translation object</param> /// ------------------------------------------------------------------------------------ protected List<ChapterVerseInfo>[] ParseBackTranslationVerses(ICmTranslation cmTrans) { if (cmTrans == null) return null; // Create the main array, with one element for each desired WS List<ChapterVerseInfo>[] btCvInfoByWs = new List<ChapterVerseInfo>[m_requestedAnalWS.Length]; for (int iWs = 0; iWs < m_requestedAnalWS.Length; iWs++) { // Create the array list for the back translation in this writing system btCvInfoByWs[iWs] = new List<ChapterVerseInfo>(); ITsString tss = cmTrans.Translation.get_String(m_requestedAnalWS[iWs]); if (tss == null || tss.Length == 0) continue; for (int iRun = 0; iRun < tss.RunCount; ) { // Analyze this set of runs ITsTextProps ttp = tss.get_Properties(iRun); string styleName = ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle); string numberText; int iRunMin, iRunLim; if (styleName == ScrStyleNames.VerseNumber || styleName == ScrStyleNames.ChapterNumber) { // get the number text, and trim it numberText = tss.get_RunText(iRun).Trim(); // Get the starting run index for the text following the verse/chapter number iRunMin = iRun + 1; // advance past the chapter/verse run iRun++; } else { numberText = string.Empty; // The text starts with the beginning of this run iRunMin = iRun; } iRunLim = iRun; // Find the end of the text runs until the next chapter/verse number while (iRun < tss.RunCount) { ttp = tss.get_Properties(iRun); string nextStyleName = ttp.GetStrPropValue((int)FwTextPropType.ktptNamedStyle); if (nextStyleName == ScrStyleNames.VerseNumber || nextStyleName == ScrStyleNames.ChapterNumber) { break; //we found the next number } // advance our run lim to the next run and prepare for the next run iRunLim = ++iRun; } // Create a ChapterVerseInfo element for this set of runs RefElement type; if (styleName == ScrStyleNames.VerseNumber) type = RefElement.Verse; else if (styleName == ScrStyleNames.ChapterNumber) type = RefElement.Chapter; else type = RefElement.None; // text without a chapter/verse number btCvInfoByWs[iWs].Add(new ChapterVerseInfo(type, numberText, iRunMin, iRunLim)); } } return btCvInfoByWs; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the back translation status. /// </summary> /// <param name="trans">The translation.</param> /// <param name="status">The status.</param> /// ------------------------------------------------------------------------------------ public void SetTransStatus(ICmTranslation trans, BackTranslationStatus status) { CheckDisposed(); SetBackTranslationStatus(trans, status); }
/// ------------------------------------------------------------------------------------ /// <summary> /// provide access to the "InsertTranslationUserPrompt" method /// </summary> /// <param name="vwEnv"></param> /// <param name="trans"></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public bool CallInsertBackTranslationUserPrompt(IVwEnv vwEnv, ICmTranslation trans) { return InsertTranslationUserPrompt(vwEnv, trans); }
/// ------------------------------------------------------------------------------------ /// <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="trans">translation to be displayed</param> /// <returns>true if an empty string was substituted for missing/empty StText</returns> /// ------------------------------------------------------------------------------------ protected override bool InsertTranslationUserPrompt(IVwEnv vwenv, ICmTranslation trans) { // No user prompt in any of these conditions if (trans == null || m_updatedPrompts.Contains(trans.Hvo)) // user interaction has updated prompt return false; // If there is text in the translation then do not add a prompt. if (trans.Translation.get_String(m_wsDefault).Length > 0) return false; // If there is no text in the parent paragraph then do not place a prompt in the // back translation. if (((IStTxtPara)trans.Owner).Contents.Length == 0) return false; // Insert the prompt. vwenv.NoteDependency(new int[] { trans.Hvo }, new int[] { CmTranslationTags.kflidTranslation}, 1); vwenv.AddProp(SimpleRootSite.kTagUserPrompt, this, (int)CmTranslationTags.kflidTranslation); return true; }
internal BackTranslationInfo(ICmTranslation backtran) { foreach (int ws in backtran.Cache.LangProject.AnalysisWssRC.HvoArray) { ITsString tss = backtran.Translation.GetAlternative(ws).UnderlyingTsString; if (tss.Length > 0 && tss != backtran.Translation.NotFoundTss) m_mapWsTssTran.Add(ws, tss); string status = backtran.Status.GetAlternative(ws); if (!String.IsNullOrEmpty(status) && status != backtran.Status.NotFoundTss.Text) m_mapWsTssStatus.Add(ws, status); } m_wsDefaultAnal = backtran.Cache.DefaultAnalWs; m_hvo = backtran.Hvo; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a run of text to the specified translation /// </summary> /// <param name="trans"></param> /// <param name="btWS"></param> /// <param name="runText"></param> /// <param name="runStyleName"></param> /// ------------------------------------------------------------------------------------ protected void AddRunToMockedTrans(ICmTranslation trans, int btWS, string runText, string runStyleName) { AddRunToMockedTrans(trans, btWS, btWS, runText, runStyleName); }
private void WriteTranslation(TextWriter w, ICmTranslation trans) { if (trans.TypeRA == null) w.WriteLine("<translation>"); else w.WriteLine("<translation type=\"{0}\">", BestAlternative(trans.TypeRA.Name, m_wsEn)); WriteAllForms(w, null, null, "form", trans.Translation); w.WriteLine("</translation>"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets up the back translation for the footnote paragraph. /// </summary> /// ------------------------------------------------------------------------------------ private void SetupBackTrans() { m_trans = AddBtToMockedParagraph(m_footnotePara, m_wsDe); AddBtToMockedParagraph(m_footnotePara, m_wsEs); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set up the mocked selection helper with needed level info for a translation. /// </summary> /// <param name="para">The para.</param> /// <param name="trans">The trans.</param> /// <param name="wsTrans">The ws trans.</param> /// <param name="section">The section.</param> /// <param name="book">The book.</param> /// ------------------------------------------------------------------------------------ private void SetupSelHelperLevelInfo(IStTxtPara para, ICmTranslation trans, int wsTrans, IScrSection section, IScrBook book) { SelLevInfo[] selLevInfo = new SelLevInfo[5]; selLevInfo[4].tag = m_btView.BookFilter.Tag; selLevInfo[4].ihvo = 0; selLevInfo[4].hvo = book.Hvo; selLevInfo[3].tag = ScrBookTags.kflidSections; selLevInfo[3].ihvo = 0; selLevInfo[3].hvo = section.Hvo; selLevInfo[2].ihvo = 0; selLevInfo[2].tag = ScrSectionTags.kflidContent; selLevInfo[1].ihvo = 0; selLevInfo[1].hvo = para.Hvo; selLevInfo[1].tag = StTextTags.kflidParagraphs; selLevInfo[0].ihvo = 0; selLevInfo[0].hvo = trans.Hvo; selLevInfo[0].ws = 0; //not useful, but that's what actual selLevelInfo[0] has selLevInfo[0].tag = -1; //not useful, but that's what actual selLevelInfo[0] has m_selHelper.SetupResult("LevelInfo", selLevInfo); m_selHelper.SetupResult("GetLevelInfo", selLevInfo, new Type[] { typeof(SelectionHelper.SelLimitType) }); m_selHelper.SetupResult("NumberOfLevels", 5); }
private void SetupSelForVerseInsert(int ichInitial, ICmTranslation trans, int wsBT) { #if DEBUG m_selHelper.SetupResult("IsRange", false); #endif m_selHelper.SetupResult("IchAnchor", ichInitial); m_selHelper.SetupResult("IchEnd", ichInitial); m_selHelper.Expect("SetIPAfterUOW"); ITsString tssTrans = trans.Translation.get_String(wsBT); m_sel.ExpectAndReturn("TextSelInfo", null, m_TextSelInfoArgs_anchor, m_TextSelInfoTypes, new object[] { true, tssTrans, ichInitial, false, trans.Hvo, kflidTrans, wsBT }); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Access the ParseBackTranslationVerses method /// </summary> /// ------------------------------------------------------------------------------------ public new List<ChapterVerseInfo>[] ParseBackTranslationVerses(ICmTranslation cmTrans) { CheckDisposed(); return base.ParseBackTranslationVerses(cmTrans); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a back translation footnote in the given translation for the given footnote. /// Inserts a ref ORC in the translation and sets the the BT text in the footnote. /// </summary> /// <param name="trans">The given back translation of an StTxtPara</param> /// <param name="ichPos">The 0-based character offset into the back translation string /// at which we will insert the reference ORC</param> /// <param name="ws">writing system of the BT and ORC</param> /// <param name="footnote">The given footnote</param> /// <param name="footnoteBtText">text for the back translation of the footnote</param> /// <returns>the back translation of the given footnote</returns> /// ------------------------------------------------------------------------------------ public ICmTranslation AddFootnoteORCtoTrans(ICmTranslation trans, int ichPos, int ws, StFootnote footnote, string footnoteBtText) // TODO: rename this method to AddBtFootnote(), so it reads similar to AddFootnote() in tests { CheckDisposed(); AddFootnoteORCtoTrans(trans, ichPos, ws, footnote); // Add the given footnote BT text to the footnote. IStTxtPara para = (IStTxtPara)footnote.ParagraphsOS[0]; ICmTranslation footnoteTrans = para.GetOrCreateBT(); ITsStrBldr tssFootnoteBldr = footnoteTrans.Translation.GetAlternative(ws).UnderlyingTsString.GetBldr(); tssFootnoteBldr.ReplaceRgch(0, 0, footnoteBtText, footnoteBtText.Length, StyleUtils.CharStyleTextProps(null, ws)); footnoteTrans.Translation.SetAlternative(tssFootnoteBldr.GetString(), ws); return footnoteTrans; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set the status of a back translation object. /// </summary> /// <param name="trans"></param> /// <param name="status"></param> /// ------------------------------------------------------------------------------------ protected void SetBackTranslationStatus(ICmTranslation trans, BackTranslationStatus status) { Debug.Assert(trans.TypeRA.Guid == LangProject.kguidTranBackTranslation); string undo; string redo; TeResourceHelper.MakeUndoRedoLabels("kstidUndoRedoChangeBackTransStatus", out undo, out redo); using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(this, undo, redo, false)) { trans.Status.SetAlternative(status.ToString(), ViewConstructorWS); m_fdoCache.MainCacheAccessor.PropChanged(null, (int)PropChangeType.kpctNotifyAll, trans.Hvo, (int)CmTranslation.CmTranslationTags.kflidStatus, 0, 1, 1); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a back translation footnote ref ORC in the given translation for the given footnote /// </summary> /// <param name="trans">The given translation, usually a back translation</param> /// <param name="ichPos">The 0-based character offset into the translation string /// at which we will insert the reference ORC</param> /// <param name="ws">writing system of the ORC</param> /// <param name="footnote">The given footnote</param> /// ------------------------------------------------------------------------------------ public void AddFootnoteORCtoTrans(ICmTranslation trans, int ichPos, int ws, StFootnote footnote) { CheckDisposed(); // Insert a footnote reference ORC into the given translation string ITsStrBldr tsStrBldr = trans.Translation.GetAlternative(ws).UnderlyingTsString.GetBldr(); footnote.InsertRefORCIntoTrans(tsStrBldr, ichPos, ws); trans.Translation.SetAlternative(tsStrBldr.GetString(), ws); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets up the back translation for the footnote paragraph. /// </summary> /// ------------------------------------------------------------------------------------ private void SetupBackTrans() { m_trans = m_scrInMemoryCache.AddBtToMockedParagraph(m_footnotePara, m_wsDe); m_scrInMemoryCache.AddBtToMockedParagraph(m_footnotePara, m_wsEs); }
private void SetupSelRangeForChapterInsert(int ichInitial, int ichEnd, ICmTranslation trans, int wsBT) { m_selHelper.SetupResult("IchAnchor", ichInitial); m_selHelper.SetupResult("IchEnd", ichEnd); m_selHelper.SetupResult("IsValid", true); ITsString tssTrans = trans.Translation.get_String(wsBT); m_sel.SetupResult("SelType", VwSelType.kstText); m_sel.SetupResultForParams("TextSelInfo", null, m_TextSelInfoArgs, m_TextSelInfoTypes, new object[] { true, tssTrans, Math.Min(ichInitial, ichEnd), false, trans.Hvo, CmTranslationTags.kflidTranslation, wsBT }); m_sel.SetupResultForParams("TextSelInfo", null, new object[] { false, null, null, null, null, null, null }, m_TextSelInfoTypes, new object[] { false, tssTrans, Math.Max(ichInitial, ichEnd), false, trans.Hvo, CmTranslationTags.kflidTranslation, wsBT }); m_sel.SetupResult("IsRange", true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set the status of a back translation object. /// </summary> /// <param name="trans"></param> /// <param name="status"></param> /// ------------------------------------------------------------------------------------ protected void SetBackTranslationStatus(ICmTranslation trans, BackTranslationStatus status) { Debug.Assert(trans.TypeRA.Guid == LangProjectTags.kguidTranBackTranslation); trans.Status.set_String(ViewConstructorWS, status.ToString()); // We shouldn't have to do this in the new FDO //m_fdoCache.MainCacheAccessor.PropChanged(null, // (int)PropChangeType.kpctNotifyAll, trans.Hvo, // CmTranslationTags.kflidStatus, 0, 1, 1); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Output the fields of a back translation heading paragraph. This is used for Toolbox /// markup only, to output the back translation of title or section head after the /// vernacular paragraph is already output. /// Special \btxx markers are used, including a \btxx paragraph marker. /// </summary> /// <param name="paraMarker">the paragraph marker that was used for the vernacular</param> /// <param name="backTranslation">the back translation structured string /// paragraph</param> /// <remarks>You might think about refactoring to eliminate this method and instead use /// ExportBackTransForPriorVerse(backTranslation, btVersesByWs, RefElement.None, /// tring.Empty), but it would have to be enhanced to optionally put out a paraMarker if /// given one, handle Secondary Titles specially, and perhaps use kNoCharStyleMarker /// instead of kVerseTextMarker for headings. It would probably get ugly.</remarks> /// ------------------------------------------------------------------------------------ private void ExportBackTransForHeadingPara(string paraMarker, ICmTranslation backTranslation) { Debug.Assert(paraMarker != null); for (int iWs = 0; iWs < m_requestedAnalWS.Length; iWs++) { // set flag to give us a new para marker for this ws bool fParaMarkerWritten = false; // prepare our icuSuffix string icuSuffix; if (m_requestedAnalWS.Length == 1 || m_requestedAnalWS[iWs] == m_defaultAnalWS) icuSuffix = string.Empty; else icuSuffix = @"_" + m_icuLocales[iWs]; // Get the TS String for the back translation in the requested WS ITsString tssBt = backTranslation.Translation.get_String(m_requestedAnalWS[iWs]); if (tssBt.Length == 0) continue; // Output each run for (int iRun = 0; iRun < tssBt.RunCount; iRun++) { ITsTextProps runProps = tssBt.get_Properties(iRun); string charStyleName = runProps.GetStrPropValue( (int)FwTextPropType.ktptNamedStyle); string runText = tssBt.get_RunText(iRun).TrimStart(); string markerCharStyle; // Handle secondary and tertiary title char styles as if they were paragraph styles. // This may happen before we output the \mt paragraph marker. if (charStyleName == ScrStyleNames.SecondaryBookTitle || charStyleName == ScrStyleNames.TertiaryBookTitle) { markerCharStyle = GetMarkerForStyle(charStyleName); m_file.WriteLine(kBackTransMarkerPrefix + markerCharStyle.Substring(1) + icuSuffix + " " + runText); continue; // done with this run } // Build a back-translation marker(\btxx_ws) from a vernacular marker and output the field if (charStyleName != null) { // we have a character style markerCharStyle = GetMarkerForStyle(charStyleName); // if we haven't yet, we need to get the paragraph marker written first if (!fParaMarkerWritten) m_file.WriteLine(kBackTransMarkerPrefix + paraMarker.Substring(1) + icuSuffix); // now output the char marker and text m_file.WriteLine(kBackTransMarkerPrefix + markerCharStyle.Substring(1) + icuSuffix + " " + runText); } else // we have no character style { // we'll use the paragraph marker, or the kNoCharStyleMarker string subMarker = (fParaMarkerWritten) ? kNoCharStyleMarker : paraMarker; m_file.WriteLine(kBackTransMarkerPrefix + subMarker.Substring(1) + icuSuffix + " " + runText); } fParaMarkerWritten = true; } } }