示例#1
0
        /// <summary>
        /// Given a segment which points into your paragraph, return the string that should correspond to it in the BT.
        /// </summary>
        /// <param name="seg"></param>
        /// <returns></returns>
        string ConvertedBtLabel(ICmBaseAnnotation seg)
        {
            ITsString tssResult = m_scr.ConvertCVNumbersInStringForBT((seg as CmBaseAnnotation).TextAnnotated, m_wsBt);

            if (tssResult == null)
            {
                return(null);                // paranoia.
            }
            return(tssResult.Text);
        }
示例#2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Given that segment is a 'label' segment (typically an embedded identifying number),
        /// figure out what to display as the corresponding label in a back translation view.
        /// This is made separate so that TeStVc can override to use a different numbering scheme
        /// in the BT.
        /// </summary>
        /// <param name="segment"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        protected override ITsString GetBackTransLabelText(ISegment segment)
        {
            ITsString tssLabel = segment.BaselineText;

            if (tssLabel == null)
            {
                return(null);
            }
            IScripture scr = segment.Cache.LangProject.TranslatedScriptureOA;

            return(scr.ConvertCVNumbersInStringForBT(tssLabel, BackTranslationWS));
        }
示例#3
0
 /// <summary>
 /// Given a segment which points into your paragraph, return the string that should correspond to it in the BT.
 /// </summary>
 /// <param name="seg"></param>
 /// <returns></returns>
 ITsString ConvertedBtLabel(ISegment seg)
 {
     return(m_scr.ConvertCVNumbersInStringForBT(seg.BaselineText, m_wsBt));
 }
示例#4
0
        public static void UpdateMainTransFromSegmented(StTxtPara para, int[] wss)
        {
            if (!para.IsValidObject())
            {
                return;                 // in merge, paragraph may be modified then deleted.
            }
            FdoCache cache = para.Cache;

            BtConverter.EnsureMainParaSegments(para, wss[0]);
            ISilDataAccess sda         = cache.MainCacheAccessor;
            List <int>     segments    = para.Segments;
            int            kflidFT     = StTxtPara.SegmentFreeTranslationFlid(cache);
            ITsString      tssContents = para.Contents.UnderlyingTsString;
            IScripture     scr         = para.Cache.LangProject.TranslatedScriptureOA;
            ICmTranslation originalBT  = para.GetBT();            // Can be null
            string         sUnfinished = BackTranslationStatus.Unfinished.ToString();

            foreach (int ws in wss)
            {
                ITsStrBldr bldr          = TsStrBldrClass.Create();
                bool       wantNextSpace = false;        // suppresses space before the first thing we add.
                bool       haveBtText    = false;        // Text that isn't segment label text
                foreach (int hvoSeg in segments)
                {
                    // If it's a label, insert it directly. Suppress following space.
                    int       beginOffset = sda.get_IntProp(hvoSeg, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset);
                    int       endOffset   = sda.get_IntProp(hvoSeg, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset);
                    ITsString tssFt;
                    // Whether we want to insert a space before the current segment is determined by the previous one.
                    // Save that value so we can set wantSpace appropriately for the following one.
                    bool wantSpace = wantNextSpace;
                    if (SegmentBreaker.HasLabelText(tssContents, beginOffset, endOffset))
                    {
                        tssFt         = (new CmBaseAnnotation(cache, hvoSeg)).TextAnnotated;
                        tssFt         = scr.ConvertCVNumbersInStringForBT(CorrectFootnotes(tssFt), ws);
                        wantNextSpace = false;
                    }
                    else
                    {
                        int hvoFt = sda.get_ObjectProp(hvoSeg, kflidFT);
                        tssFt         = sda.get_MultiStringAlt(hvoFt, (int)CmAnnotation.CmAnnotationTags.kflidComment, ws);
                        haveBtText   |= (tssFt.Length > 0);
                        wantNextSpace = EndsWithNonSpace(tssFt);
                    }
                    if (tssFt.Length > 0)
                    {
                        if (wantSpace)
                        {
                            // The preceding segment should typically be followed by a space.
                            if (!StartsWithSpaceOrOrc(tssFt))
                            {
                                bldr.Replace(bldr.Length, bldr.Length, " ", null);
                            }
                        }
                        bldr.ReplaceTsString(bldr.Length, bldr.Length, tssFt);
                    }
                }

                // If the back translation doesn't have text, we don't want to create verse
                // segment labels. This prevents the problem where the book thinks it has a
                // back translation because of automatically generated verse labels (TE-8283).
                if (!haveBtText)
                {
                    // This check might not be needed, but it shouldn't hurt anything.
                    if (originalBT != null)
                    {
                        if (originalBT.Translation.GetAlternative(ws).Length > 0)
                        {
                            string origStatus = originalBT.Status.GetAlternative(ws);
                            if (!String.IsNullOrEmpty(origStatus) && origStatus != sUnfinished)
                            {
                                originalBT.Status.SetAlternative(sUnfinished, ws);
                            }
                        }
                    }
                    continue;
                }

                ITsString      newFt = bldr.GetString();
                ICmTranslation trans;
                if (newFt.Length == 0)
                {
                    trans = para.GetBT();
                    if (trans == null)
                    {
                        return;                         // don't bother creating one to store an empty translation!
                    }
                }
                else
                {
                    trans = para.GetOrCreateBT();
                }
                // Don't write unless it changed...PropChanged can be expensive.
                if (!trans.Translation.GetAlternative(ws).UnderlyingTsString.Equals(newFt))
                {
                    trans.Translation.SetAlternative(newFt, ws);
                    trans.Status.SetAlternative(sUnfinished, ws);
                }
            }
        }