Translating a batch of text lines

A batch is a collection of text lines. In this example we will translate a batch of 3 sentences using the translation web service, which takes a batch as input and returns the same translated batch as output.
 
inBatch = New YMTS.Batch
outBatch = New YMTS.Batch
YMTSService = New YMTS.YMTS
 
outBatch = YMTSService.Translate(inBatch)
 

Choosing the MT engine

Before we call the translate function, we first have to create an engine:
 
engine = New YMTS.Engine
engine.SourceLanguage = "de"
engine.TargetLanguage = "en"
engine.Description = "YEU_cars_en_fr"
 
Now that we have created an engine, we assign it to the input batch
inBatch.Engine = engine
 

Choosing the MT options

We can give several instructions to the translation webservice, for example we can tag untranslatables or glossary terms and choose how to tag them:

options As New YMTS.Options
options.TagUntranslatables = True
options.TagGlossaryTerms = True
options.GlossTag = "DICT"
options.UntranslatableTag = "UNTR"
 
Now that we have created the options, we assign it to the input batch
 
inBatch.Options = options
 

Adding text lines to the batch

To add the text we want to translate to the batch we build an array of text lines, in this example we add 3 textlines

textLines= new YMTS.TextLine[3]
textline1 = New YMTS.TextLine
textline1.Source = "Easy to use, just add to the equipments fuel tank"
textLines [0] = textline1
textline2 = New YMTS.TextLine
textline2.Source = "Ideal for all small 2-cycle and 4-cycle engines"
textLines [1] = textline2
textline3 = New YMTS.TextLine
textline3.Source = "Removes water from fuel and prevents rust and corrosion"
textLines [2] = textline3
 
Finally add the textlines to the batch:
 
inBatch.TextLines = textLines
 

Reading the translation

When we call the translation web service on the input batch we get the output batch that contains the translations as well as meta data about each textline and the batch, for example:
 
outBatch = YMTSService.Translate(inBatch)
outBatch.Response.Status
outBatch.Response.FailureReason
outBatch.TextLines[0].Translation
outBatch.TextLines[0].WordCountTranslation
outBatch.TextLines[1].Translation
outBatch.TextLines[1].WordCountTranslation
outBatch.TextLines[2].Translation
outBatch.TextLines[2].WordCountTranslation