@@ -35,19 +35,35 @@ CancellationToken cancellationToken
3535        List < PreTranslation >  preTranslations  =  [ ] ; 
3636
3737        // Ensure we have the parameters to retrieve the pre-translation 
38-         ( string ?  translationEngineId ,  string  corpusId ,  bool  useParatextVerseRef )  = 
38+         ( string ?  translationEngineId ,  string ?  corpusId ,   string ?   parallelCorpusId ,  bool  useParatextVerseRef )  = 
3939            await  GetPreTranslationParametersAsync ( sfProjectId ) ; 
4040
4141        // Get the pre-translation data from Serval 
4242        string  textId  =  useParatextVerseRef  ?  GetTextId ( bookNum )  :  GetTextId ( bookNum ,  chapterNum ) ; 
43-         foreach  ( 
44-             Pretranslation  preTranslation  in  await  translationEnginesClient . GetAllPretranslationsAsync ( 
43+         IList < Pretranslation >  servalPreTranslations ; 
44+         if  ( parallelCorpusId  is  not null ) 
45+         { 
46+             servalPreTranslations  =  await  translationEnginesClient . GetAllPretranslationsAsync ( 
47+                 translationEngineId , 
48+                 parallelCorpusId , 
49+                 textId , 
50+                 cancellationToken 
51+             ) ; 
52+         } 
53+         else 
54+         { 
55+             // Retrieve the pre-translations from a legacy corpus 
56+ #pragma warning disable CS0612  // Type or member is obsolete 
57+             servalPreTranslations  =  await  translationEnginesClient . GetAllCorpusPretranslationsAsync ( 
4558                translationEngineId , 
4659                corpusId , 
4760                textId , 
4861                cancellationToken 
49-             ) 
50-         ) 
62+             ) ; 
63+ #pragma warning restore CS0612  // Type or member is obsolete 
64+         } 
65+ 
66+         foreach  ( Pretranslation  preTranslation  in  servalPreTranslations ) 
5167        { 
5268            // A reference will be in one of the formats: 
5369            // FileFormat.Text: "40_1:verse_001_002" 
@@ -185,30 +201,55 @@ CancellationToken cancellationToken
185201    ) 
186202    { 
187203        // Ensure we have the parameters to retrieve the pre-translation 
188-         ( string ?  translationEngineId ,  string  corpusId ,  bool  _ )  =  await  GetPreTranslationParametersAsync ( sfProjectId ) ; 
204+         ( string ?  translationEngineId ,  string ?  corpusId ,  string ?  parallelCorpusId ,  bool  _ )  = 
205+             await  GetPreTranslationParametersAsync ( sfProjectId ) ; 
206+ 
207+         // Generate the paragraph marker and quote normalization behaviors 
208+         PretranslationUsfmMarkerBehavior  paragraphMarkerBehavior  =  config . ParagraphFormat  switch 
209+         { 
210+             ParagraphBreakFormatOptions . Remove  =>  PretranslationUsfmMarkerBehavior . Strip , 
211+             ParagraphBreakFormatOptions . BestGuess  =>  PretranslationUsfmMarkerBehavior . PreservePosition , 
212+             ParagraphBreakFormatOptions . MoveToEnd  =>  PretranslationUsfmMarkerBehavior . Preserve , 
213+             _ =>  PretranslationUsfmMarkerBehavior . PreservePosition , 
214+         } ; 
215+         PretranslationNormalizationBehavior  quoteNormalizationBehavior  =  config . QuoteFormat  switch 
216+         { 
217+             QuoteStyleOptions . Denormalized  =>  PretranslationNormalizationBehavior . Denormalized , 
218+             QuoteStyleOptions . Normalized  =>  PretranslationNormalizationBehavior . Normalized , 
219+             _ =>  PretranslationNormalizationBehavior . Denormalized , 
220+         } ; 
189221
190222        // Get the USFM 
191-         string  usfm  =  await  translationEnginesClient . GetPretranslatedUsfmAsync ( 
192-             id :  translationEngineId , 
193-             corpusId :  corpusId , 
194-             textId :  GetTextId ( bookNum ) , 
195-             textOrigin :  PretranslationUsfmTextOrigin . OnlyPretranslated , 
196-             template :  PretranslationUsfmTemplate . Source , 
197-             paragraphMarkerBehavior :  config . ParagraphFormat  switch 
198-             { 
199-                 ParagraphBreakFormatOptions . Remove  =>  PretranslationUsfmMarkerBehavior . Strip , 
200-                 ParagraphBreakFormatOptions . BestGuess  =>  PretranslationUsfmMarkerBehavior . PreservePosition , 
201-                 ParagraphBreakFormatOptions . MoveToEnd  =>  PretranslationUsfmMarkerBehavior . Preserve , 
202-                 _ =>  PretranslationUsfmMarkerBehavior . PreservePosition , 
203-             } , 
204-             quoteNormalizationBehavior :  config . QuoteFormat  switch 
205-             { 
206-                 QuoteStyleOptions . Denormalized  =>  PretranslationNormalizationBehavior . Denormalized , 
207-                 QuoteStyleOptions . Normalized  =>  PretranslationNormalizationBehavior . Normalized , 
208-                 _ =>  PretranslationNormalizationBehavior . Denormalized , 
209-             } , 
210-             cancellationToken :  cancellationToken 
211-         ) ; 
223+         string  usfm ; 
224+         if  ( parallelCorpusId  is  not null ) 
225+         { 
226+             usfm  =  await  translationEnginesClient . GetPretranslatedUsfmAsync ( 
227+                 id :  translationEngineId , 
228+                 parallelCorpusId :  parallelCorpusId , 
229+                 textId :  GetTextId ( bookNum ) , 
230+                 textOrigin :  PretranslationUsfmTextOrigin . OnlyPretranslated , 
231+                 template :  PretranslationUsfmTemplate . Source , 
232+                 paragraphMarkerBehavior :  paragraphMarkerBehavior , 
233+                 quoteNormalizationBehavior :  quoteNormalizationBehavior , 
234+                 cancellationToken :  cancellationToken 
235+             ) ; 
236+         } 
237+         else 
238+         { 
239+             // Retrieve the USFM from a legacy corpus 
240+ #pragma warning disable CS0612  // Type or member is obsolete 
241+             usfm  =  await  translationEnginesClient . GetCorpusPretranslatedUsfmAsync ( 
242+                 id :  translationEngineId , 
243+                 corpusId :  corpusId , 
244+                 textId :  GetTextId ( bookNum ) , 
245+                 textOrigin :  PretranslationUsfmTextOrigin . OnlyPretranslated , 
246+                 template :  PretranslationUsfmTemplate . Source , 
247+                 paragraphMarkerBehavior :  paragraphMarkerBehavior , 
248+                 quoteNormalizationBehavior :  quoteNormalizationBehavior , 
249+                 cancellationToken :  cancellationToken 
250+             ) ; 
251+ #pragma warning restore CS0612  // Type or member is obsolete 
252+         } 
212253
213254        // Return the entire book 
214255        if  ( chapterNum  ==  0 ) 
@@ -241,19 +282,34 @@ public async Task UpdatePreTranslationStatusAsync(string sfProjectId, Cancellati
241282        } 
242283
243284        // Ensure we have the parameters to retrieve the pre-translation 
244-         ( string ?  translationEngineId ,  string  corpusId ,  bool  useParatextVerseRef )  = 
285+         ( string ?  translationEngineId ,  string  corpusId ,  string   parallelCorpusId ,   bool  useParatextVerseRef )  = 
245286            await  GetPreTranslationParametersAsync ( sfProjectId ) ; 
246287
247288        // Get all the pre-translations and update the chapters 
248-         Dictionary < int ,  HashSet < int > >  bookChapters  =  [ ] ; 
249-         foreach  ( 
250-             Pretranslation  preTranslation  in  await  translationEnginesClient . GetAllPretranslationsAsync ( 
289+         IList < Pretranslation >  preTranslations ; 
290+         if  ( parallelCorpusId  is  not null ) 
291+         { 
292+             preTranslations  =  await  translationEnginesClient . GetAllPretranslationsAsync ( 
293+                 translationEngineId , 
294+                 parallelCorpusId , 
295+                 textId :  null , 
296+                 cancellationToken 
297+             ) ; 
298+         } 
299+         else 
300+         { 
301+             // Retrieve the pre-translations from a legacy corpus 
302+ #pragma warning disable CS0612  // Type or member is obsolete 
303+             preTranslations  =  await  translationEnginesClient . GetAllCorpusPretranslationsAsync ( 
251304                translationEngineId , 
252305                corpusId , 
253306                textId :  null , 
254307                cancellationToken 
255-             ) 
256-         ) 
308+             ) ; 
309+ #pragma warning restore CS0612  // Type or member is obsolete 
310+         } 
311+         Dictionary < int ,  HashSet < int > >  bookChapters  =  [ ] ; 
312+         foreach  ( Pretranslation  preTranslation  in  preTranslations ) 
257313        { 
258314            // Get the book and chapter number 
259315            int  bookNum ; 
@@ -339,7 +395,8 @@ await projectDoc.SubmitJson0OpAsync(op =>
339395    /// <exception cref="DataNotFoundException">The pre-translation engine is not configured, or the project secret cannot be found.</exception> 
340396    protected  internal  virtual  async  Task < ( 
341397        string  translationEngineId , 
342-         string  corpusId , 
398+         string ?  corpusId , 
399+         string ?  parallelCorpusId , 
343400        bool  useParatextVerseRef 
344401    ) >  GetPreTranslationParametersAsync ( string  sfProjectId ) 
345402    { 
@@ -350,11 +407,12 @@ bool useParatextVerseRef
350407        } 
351408
352409        string  translationEngineId  =  projectSecret . ServalData ? . PreTranslationEngineId ; 
353-         string  corpusId ; 
410+         string ?  corpusId  =  null ; 
411+         string ?  parallelCorpusId  =  null ; 
354412        bool  useParatextVerseRef  =  false ; 
355413        if  ( ! string . IsNullOrWhiteSpace ( projectSecret . ServalData ? . ParallelCorpusIdForPreTranslate ) ) 
356414        { 
357-             corpusId  =  projectSecret . ServalData . ParallelCorpusIdForPreTranslate ; 
415+             parallelCorpusId  =  projectSecret . ServalData . ParallelCorpusIdForPreTranslate ; 
358416            useParatextVerseRef  =  true ; 
359417        } 
360418        else 
@@ -369,11 +427,14 @@ bool useParatextVerseRef
369427            } 
370428        } 
371429
372-         if  ( string . IsNullOrWhiteSpace ( translationEngineId )  ||  string . IsNullOrWhiteSpace ( corpusId ) ) 
430+         if  ( 
431+             string . IsNullOrWhiteSpace ( translationEngineId ) 
432+             ||  ( string . IsNullOrWhiteSpace ( corpusId )  &&  string . IsNullOrWhiteSpace ( parallelCorpusId ) ) 
433+         ) 
373434        { 
374435            throw  new  DataNotFoundException ( "The pre-translation engine is not configured." ) ; 
375436        } 
376437
377-         return  ( translationEngineId ,  corpusId ,  useParatextVerseRef ) ; 
438+         return  ( translationEngineId ,  corpusId ,  parallelCorpusId ,   useParatextVerseRef ) ; 
378439    } 
379440} 
0 commit comments