Translate Text

Translate

To begin, you must first instantiate the Translator class. This is the mandatory first step for all operations within the Lara SDK.

Initialization Guide →

Translates text from a source language to a target language. It supports single-sentence translations, context-aware translations and adaptation to specific translation memories.

Request

res = lara.translate('Hello, how are you?',
    source='en-US',
    target='it-IT',
    profanitiesDetect: "source_target",
    profanitiesHandling: "detect",
    adapt_to=['mem_1_id', 'mem_2_id'],
    glossaries=['gls_1_id', 'gls_2_id'],
    instructions=['Be formal'],
    style="fluid",
    content_type='text/plain',
    timeout_ms=2000,
    priority=TranslatePriority.NORMAL,
    )

print(res.translation)
const res  = await lara.translate('Hello, how are you?', 'en-US', 'it-IT', {
        adaptTo: ['mem_1_id', 'mem_2_id'],
        glossaries: ['gls_1_id', 'gls_2_id'],
        instructions: ['Be formal'],
        profanitiesDetect: "source_target",
        profanitiesHandling: "detect",
        style: 'fluid',
        contentType: 'text/plain',
        timeoutInMillis: 2000,
        priority: 'normal'
});
// All options are optional and can be omitted
TranslateOptions options = new TranslateOptions();
options.setAdaptTo("mem_1_id", "mem_2_id");
options.setGlossaries("gls_1_id", "gls_2_id");
options.setInstructions("Be formal");
options.setProfanitiesDetect(ProfanitiesDetect.SOURCE_TARGET)
options.setProfanitiesHandling(ProfanitiesHandling.DETECT);
options.setStyle(TranslationStyle.FLUID);
options.setContentType("text/plain");
options.setTimeoutMs(2000);
options.setPriority(TranslateOptions.Priority.NORMAL);

TextResult res = lara.translate("Hello, how are you?", "en-US", "it-IT", options);
$options = new TranslateOptions([
    'adaptTo' => array('mem_1_id', 'mem_2_id'),
     'glossaries' => array('gls_1_id', 'gls_2_id'),
    'instructions' => array('Be formal'),
	  'style' => 'fluid',
    'contentType' => 'text/plain',
    'timeoutInMillis' => 2000,
    'priority' => 'normal'
]);

$res = $lara->translate('Hello, how are you?', 'en-US', 'it-IT', $options);
res, _ := lara.Translate("Hello, how are you?", "en-US", "it-IT",
	lara_sdk.TranslateOptions{
		Instructions: []string{"Be formal"},
		Style:        "fluid",
		ContentType:  "text/plain",
		TimeoutMs:    2000,
		Priority:     "normal"
  })

fmt.Println(*res.Translation.String)
// All options are optional and can be omitted
val options = TranslateOptions().apply {
    setAdaptTo("mem_1_id", "mem_2_id")
    setGlossaries("gls_1_id", "gls_2_id")
    setInstructions("Be formal")
    setStyle(TranslationStyle.FLUID)
    setContentType("text/plain")
    setTimeoutMs(2000)
    setPriority(TranslateOptions.Priority.NORMAL)
    setUseCache(TranslateOptions.UseCache.YES)
    setCacheTTL(86400)
}

val res: TextResult = lara.translate(
    "Hello, how are you?",
    "en-US",
    "it-IT",
    options
)
var res = await lara.Translate(
    "test example", "en-US", "it-IT",
new TranslateOptions {
    Instructions = new[] { "Be formal" },
    Style = TranslationStyle.Fluid,
    ContentType = "text/plain",
    TimeoutInMillis = 2000,
    Priority = TranslatePriority.Normal,
});
// All options are optional and can be omitted
let options = TranslateOptions()
    .setAdaptTo(["mem_1_id", "mem_2_id"])
    .setGlossaries(["gls_1_id", "gls_2_id"])
    .setInstructions(["Be formal"])
    .setStyle(.fluid)
    .setContentType("text/plain")
    .setTimeoutMs(2000)
    .setPriority(.normal)

let res = try await lara.translate(text: "Hello, how are you?", source: "en-US", target: "it-IT", options: options)

Here follows the basic fields for the translate method:

FieldType     Required     Default     Description
text        String |
String[] |
TextBlock[]
Yes

The text to be translated. This can be a single string or a list (up to 128 elements) of strings or TextBlock objects for incremental translation.
Use String[]orTextBlockstrictly for context-linked strings, not for batch translating unrelated texts.
sourceStringNoAutodetectedThe source language code (e.g., "en-US" for English). If not specified, the system will attempt to detect it automatically.
targetStringYes

The target language code (e.g., "it-IT" for Italian). This specifies the language you want the text translated into.

Several options are available to customize the behavior of the translate method:

FieldTypeRequiredDefaultDescription
source_hintStringNo

Used to guide language detection. Specify this when the source language is uncertain to improve detection accuracy.
adapt_toString[]NoDefault is all Memories on your accountA list of translation memory IDs for adapting the translation.
glossariesString[]No

A list of glossary IDs.
instructionsString[]No[ ]A list of instructions to adjust the network’s behavior regarding the output (e.g., "Use a formal tone"). If you plan to use instructions please carefully read here
reasoningBooleanNoFalseReasoning engine that improves translation quality
profanitiesDetectStringNo

defines the scope of the profanity filtering.
Available options: source_target target
profanitiesHandlingStringNohideSpecifies how Lara handles profanity in the translation.
Available options: detect hide avoid
styleStringNofaithfulThe style to apply to the translation. Available values: faithful fluid creative
content_typeStringNoAutodetectedSpecifies the Content-Type of the text. Available values: text/plain
text/html
application/xliff+xml
timeout_msIntegerNoNoneSpecifies the maximum allowable time (in milliseconds) to perform the translation. If the timeout is exceeded, a TimeoutException is raised.
priorityStringNoNormalSpecifies whether the translation should be executed as a normal priority task or can wait for other tasks to complete.
use_cacheBooleanNoFalse

Specifies whether the translation should be saved in the cache for future retrieval. Note: Caching is an advanced feature and is not enabled by default. To enable caching for your account, please contact our

sales team

.

cache_ttlIntegerNo2 YearsThe time-to-live (TTL) for the cache entry, specifying how long the translation will remain in the cache.
no_traceBooleanNoFalseIf set to True, source content and its translation will not be saved on our system. (AKA Incognito mode)
verboseBooleanNoFalseWhen enabled, this parameter returns additional debugging and metadata information from the engine, such as memory and glossary matches. Not recommended for production use, as it can significantly impact response times.
headersList[String, String]NoNoneAn optional object containing additional HTTP headers to include in the request. This field is primarily intended for debugging purposes and future extensibility. Use with caution. Custom headers are not required for standard usage and may be ignored or restricted by the server.

Response

# Single string
TextResult(
    content_type="text/plain",
    source_language="en",
    adapted_to=["mem_1_id", "mem_2_id"],
    translation="Ciao, come stai?"
)

# String array
TextResult(
    content_type="text/plain",
    source_language="en",
    adapted_to=["mem_1_id", "mem_2_id"],
    translation=['Ciao, come stai?', 'Che giornata meravigliosa.']
)

# TextBlock array
TextResult(
    content_type="text/plain",
    source_language="en",
    adapted_to=["mem_1_id", "mem_2_id"],
    translation=[
        TextBlock(text="Ciao, come stai?", translatable=True),
        TextBlock(text="Che giornata meravigliosa.", translatable=True)
    ]
)
// Single string
{
    contentType: 'text/plain',
    sourceLanguage: 'en-US',
    translation: 'Salve, come sta?',
    adaptedTo: [ 'mem_1_id', 'mem_2_id']
}

// String array
{
    contentType: 'text/plain',
    sourceLanguage: 'en-US',
    translation: ['Salve, come sta?', 'Che bella giornata.'],
    adaptedTo: [ 'mem_1_id', 'mem_2_id']
}

// TextBlock array
{
    contentType: 'text/plain',
    sourceLanguage: 'en-US',
    translation: [
      { text: 'Salve, come sta?', translatable: true },
      { text: 'Che bella giornata.', translatable: true }
    ],
    adaptedTo: [ 'mem_1_id', 'mem_2_id']
}
// Single string
TextResult(
    contentType="text/plain",
    sourceLanguage="en",
    adaptedTo=["mem_1_id", "mem_2_id"],
    translation="Ciao, come stai?"
)

// String array
TextResult(
    contentType="text/plain",
    sourceLanguage="en",
    adaptedTo=["mem_1_id", "mem_2_id"],
    translation=['Ciao, come stai?', 'Che giornata meravigliosa.']
)

// TextBlock array
TextResult(
    contentType="text/plain",
    sourceLanguage="en",
    adaptedTo=["mem_1_id", "mem_2_id"],
    translation=[
        TextBlock(text="Ciao, come stai?", translatable=true),
        TextBlock(text="Che giornata meravigliosa.", translatable=true)
    ]
)
// Single string
Lara\TextResult {
    contentType: 'text/plain',
    sourceLanguage: 'en-US',
    translation: 'Salve, come sta?',
    adaptedTo: [ 'mem_1_id', 'mem_2_id']
}

// String array
Lara\TextResult {
    contentType: 'text/plain',
    sourceLanguage: 'en-US',
    translation: ['Salve, come sta?', 'Che bella giornata.'],
    adaptedTo: [ 'mem_1_id', 'mem_2_id']
}

// TextBlock array
Lara\TextResult {
    contentType: 'text/plain',
    sourceLanguage: 'en-US',
    translation: [
        Lara\TextBlock { text: 'Salve, come sta?', translatable: true },
        Lara\TextBlock { text: 'Che bella giornata.', translatable: true }
    ],
    adaptedTo: [ 'mem_1_id', 'mem_2_id']
}
// Single string
TextResult{
    ContentType:    "text/plain",
    SourceLanguage: "en-US",
    Translation: Translation{
        String: &"Salve, come sta?",
    },
    AdaptedTo: []string{"mem_1_id", "mem_2_id"},
}

// String array
TextResult{
    ContentType:    "text/plain",
    SourceLanguage: "en-US",
    Translation: Translation{
        Strings: []string{"Salve, come sta?", "Che bella giornata."},
    },
    AdaptedTo: []string{"mem_1_id", "mem_2_id"},
}

// TextBlock array
TextResult{
    ContentType:    "text/plain",
    SourceLanguage: "en-US",
    Translation: Translation{
        TextBlocks: []TextBlock{
            {Text: "Salve, come sta?", Translatable: true},
            {Text: "Che bella giornata.", Translatable: true},
        },
    },
    AdaptedTo: []string{"mem_1_id", "mem_2_id"},
}
// Single string
val single = TextResult(
    contentType = "text/plain",
    sourceLanguage = "en",
    adaptedTo = listOf("mem_1_id", "mem_2_id"),
    translation = "Ciao, come stai?"
)

// String array
val multipleStrings = TextResult(
    contentType = "text/plain",
    sourceLanguage = "en",
    adaptedTo = listOf("mem_1_id", "mem_2_id"),
    translation = listOf("Ciao, come stai?", "Che giornata meravigliosa.")
)

// TextBlock array
val textBlocks = TextResult(
    contentType = "text/plain",
    sourceLanguage = "en",
    adaptedTo = listOf("mem_1_id", "mem_2_id"),
    translation = listOf(
        TextBlock(text = "Ciao, come stai?", translatable = true),
        TextBlock(text = "Che giornata meravigliosa.", translatable = true)
    )
)
// Single string
TextResult(
    ContentType = "text/plain",
    SourceLanguage = "en",
    AdaptedTo = new List<string> { "mem_1_id", "mem_2_id" },
    Translation = "Ciao, come stai?"
)

// String array
TextResult(
    ContentType = "text/plain",
    SourceLanguage = "en",
    AdaptedTo = new List<string> { "mem_1_id", "mem_2_id" },
    Translation = new List<string> { "Ciao, come stai?", "Che giornata meravigliosa." }
)

// TextBlock array
TextResult(
    ContentType = "text/plain",
    SourceLanguage = "en",
    AdaptedTo = new List<string> { "mem_1_id", "mem_2_id" },
    Translation = new List<TextBlock> {
        new TextBlock("Ciao, come stai?", true),
        new TextBlock("Che giornata meravigliosa.", true)
    }
)
// Single string
TextResult(
    contentType: "text/plain",
    sourceLanguage: "en",
    translation: TranslatedValue(translation: "Ciao, come stai?"),
    adaptedTo: ["mem_1_id", "mem_2_id"]
)

// String array
TextResult(
    contentType: "text/plain",
    sourceLanguage: "en", 
    translation: TranslatedValue(translations: ["Ciao, come stai?", "Che giornata meravigliosa."]),
    adaptedTo: ["mem_1_id", "mem_2_id"]
)

// TextBlock array
TextResult(
    contentType: "text/plain",
    sourceLanguage: "en",
    translation: TranslatedValue(translationBlocks: [
        TextBlock(text: "Ciao, come stai?", translatable: true),
        TextBlock(text: "Che giornata meravigliosa.", translatable: true)
    ]),
    adaptedTo: ["mem_1_id", "mem_2_id"]
)
❗️

XLIFF support

Support for the application/xliff+xml content type is limited to text and a specific set of inline tags within the <source> element:

XLIFF 1.2:<g>, <x>, <ex>, <bx>, <ph>, <it>, and <mrk>.

XLIFF 2.0: <cp>, <ph>, <pc>, <sc>, <ec>, <sm>, <em> and <mrk>.

For all other tags or advanced XLIFF features, please use the Document Translation service.

Reasoning (Lara Think)

Lara Think is an advanced AI translation model that performs multi-step linguistic analysis across all available project assets, including glossaries, style guides, and contextual metadata.

This approach enables automatic detection and correction of approximately 80% of major linguistic issues, improving terminology consistency and stylistic accuracy compared to standard models.

Lara Think requires significantly more computation and can result in up to a 10× increase in processing time. It is best suited for workflows where translation quality and consistency are prioritized over latency.

Availability & Pricing

As a result of its higher computational cost, Lara Think is available on the plans below. Pricing is calculated per one million source characters.

PlanPricing (per 1M characters)
FreeNot Available
Pro€ 2000
Team€ 1500

Basic Reasoning Usage

To enable reasoning, simply pass the reasoning:true parameter within the options object. This method returns the final translation after the reasoning process is complete.

res = lara.translate('Hello, how are you?',
                     source='en-US',
                     target='it-IT',
                     style="fluid",
                     reasoning=True,
                     )

print(res.translation)
const res  = await lara.translate('Hello, how are you?', 'en-US', 'it-IT', {
        reasoning: true,
        style: 'fluid',
});
TranslateOptions options = new TranslateOptions();
options.setStyle(TranslationStyle.FLUID);
options.setReasoning(true);

TextResult res = lara.translate("Hello, how are you?", "en-US", "it-IT", options);
$options = new TranslateOptions([
    'reasoning' => true,
    'style' => 'fluid'
]);

$res = $lara->translate('Hello, how are you?', 'en-US', 'it-IT', $options);
// Sdk available soon
// Sdk available soon
var res = await lara.Translate(
    "test example", "en-US", "it-IT",
new TranslateOptions {
     Reasoning = true,
     Style = TranslationStyle.Fluid,
});
// All options are optional and can be omitted
let options = TranslateOptions()
    .setAdaptTo(["mem_1_id", "mem_2_id"])
    .setGlossaries(["gls_1_id", "gls_2_id"])
		.setReasoning(true)
    
let res = try await lara.translate(text: "Hello, how are you?", source: "en-US", target: "it-IT", options: options)

Handling Partial Results

If you want to receive the initial translation (Lara) and subsequently the refined version (Lara Think), you can implement a callback function.

The callback will be triggered as soon as the preliminary results are available, while the await will resolve with the final reasoned translation.

res = lara.translate('Hello, how are you?',
                     source='en-US',
                     target='it-IT',
                     style="fluid",
                     reasoning=True,
                     callback=lambda partial: print("translate reasoning partial:", result),
                     )

print(res.translation)
const res  = await lara.translate('Hello, how are you?', 'en-US', 'it-IT', {
        reasoning:true,
        style: 'fluid',
}, (partialResult) => console.log(partialResult)
);
TranslateOptions options = new TranslateOptions();
options.setStyle(TranslationStyle.FLUID);
options.setReasoning(true);

Consumer<TextResult> onPartial = partial ->
                        System.out.println("translate reasoning partial" + ": " + partial.getTranslation());

TextResult res = lara.translate("Hello, how are you?", "en-US", "it-IT", options, onPartial);
$lara->translate(
    "Please summarize the following: Lara translates text.",
    $source, $target,
    new TranslateOptions([
        'reasoning' => true,
        'style' => 'fluid'
    ]),
    function ($partial) {
        print_r($partial);
    }
);;
// Sdk available soon
val options = TranslateOptions().apply {
    style = TranslationStyle.FLUID
    reasoning = true
}
val onPartial: Consumer<TextResult> = Consumer { partial ->
    println("translate reasoning partial: ${partial.translation}")
}
val res: TextResult = lara.translate("Hello, how are you?", "en-US", "it-IT", options, onPartial)
var result = await lara.Translate<string>(
    "Please summarize the following: Lara translates text.",
    source, target,
    new TranslateOptions
    {
        Reasoning = true,
        Style = TranslationStyle.Fluid,
    },
    partial => Console.WriteLine(partial) 
);
// Sdk available soon

Profanity filter

The profanity filter option is designed to give you control over the handling of offensive language during the translation process. Instead of simply blocking content, the service allows you to automate the detection and transformation of profanity to ensure that the final result aligns with your safety standards or specific use cases. It bridges the gap between raw translation and content moderation, making it easier to maintain a professional tone in multiple languages.

Parameters

profanitiesDetect: Defines the "where" You can choose to analyze only the generated output (target) if you are only interested in the final result, or to check both the input and the output (source_target) for more comprehensive filtering.
profanitiesHandling: Defines the "what" Determines whether the system should simply flag the terms (detect), mask them with placeholders (hide), or actively attempt to reformulate the translation to provide an appropriate alternative (avoid).