---
updatedAt: 2026-11-05T15:55:21.000Z
agentTools:
  projectIndex: https://developers.laratranslate.com/llms.txt
---

# Translate Text

Lara offers two translation modes optimized for different needs: Lara Think for maximum translation quality, and Lara Base for speed and real-time performance.<br /><br />[**Lara Think**](https://developers.laratranslate.com/docs/translate-text#lara-think) is designed for professional translation and localization workflows where translation quality takes priority over speed and cost. It applies deeper linguistic reasoning to the source content and available context, delivering translations that approach human translation quality across many use cases. To give you precise control over this process, Lara Think allows you to set a reasoning effort across three levels (low, medium, and high), letting you balance the depth of linguistic analysis. Additionally, you can now provide an image as context, equipping the engine with visual references to further enhance the accuracy of the localized output. <br />By reducing the amount of content that requires human revision, Lara Think can significantly lower post-editing effort, costs, and time to market.<br /><br />**Lara Base&#x20;**&#x69;s Lara’s best-in-class machine translation model, optimized for speed, low latency, and high-throughput applications. It delivers high-quality translations quickly, making it the recommended choice for real-time experiences and workflows where immediate results matter.<br />[**Lara Prosa**](https://developers.laratranslate.com/docs/translate-text#lara-prosa) could be applied in post-processing after Base. It refines the output according to a style guide, preserving meaning, terminology, and consistency. It is the right choice when the final text must respect a brand voice, an authorial style, or a specific editorial standard.

## 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 →](https://developers.laratranslate.com/docs/translator-class)

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

```python
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)
```
```typescript
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'
});
```
```java
// 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);
```
```php
$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);
```
```go
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)
```
```kotlin
// 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
)
```
```csharp
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,
});
```
```swift
// 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:

<Table align={["left","left","left","left","left"]}>
  <thead>
    <tr>
      <th>
        Field
      </th>

      <th>
        Type     
      </th>

      <th>
        Required     
      </th>

      <th>
        Default     
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        text        
      </td>

      <td>
        String | <br /> String\[] | <br /> TextBlock\[]
      </td>

      <td>
        Yes
      </td>

      <td>
        -
      </td>

      <td>
        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.<br />**Use** `String[]`**or**`TextBlock`**strictly for context-linked strings, not for batch translating unrelated texts**.
      </td>
    </tr>

    <tr>
      <td>
        source
      </td>

      <td>
        String
      </td>

      <td>
        No
      </td>

      <td>
        Autodetected
      </td>

      <td>
        The source language code (e.g., "en-US" for English). If not specified, the system will attempt to detect it automatically.
      </td>
    </tr>

    <tr>
      <td>
        target
      </td>

      <td>
        String
      </td>

      <td>
        Yes
      </td>

      <td>
        -
      </td>

      <td>
        The target language code (e.g., "it-IT" for Italian). This specifies the language you want the text translated into.
      </td>
    </tr>
  </tbody>
</Table>

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

<Table align={["left","left","left","left","left"]}>
  <thead>
    <tr>
      <th>
        Field
      </th>

      <th>
        Type
      </th>

      <th>
        Required
      </th>

      <th>
        Default
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        source_hint
      </td>

      <td>
        String
      </td>

      <td>
        No
      </td>

      <td>
        -
      </td>

      <td>
        Used to guide language detection. Specify this when the source language is uncertain to improve detection accuracy.
      </td>
    </tr>

    <tr>
      <td>
        adapt_to
      </td>

      <td>
        String\[]
      </td>

      <td>
        No
      </td>

      <td>
        Default is **all Memories on your account**
      </td>

      <td>
        A list of translation memory IDs for adapting the translation.
      </td>
    </tr>

    <tr>
      <td>
        glossaries
      </td>

      <td>
        String\[]
      </td>

      <td>
        No
      </td>

      <td>
        -
      </td>

      <td>
        A list of glossary IDs.
      </td>
    </tr>

    <tr>
      <td>
        instructions
      </td>

      <td>
        String\[]
      </td>

      <td>
        No
      </td>

      <td>
        \[ ]
      </td>

      <td>
        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](https://developers.laratranslate.com/docs/adapt-to-instructions)_
      </td>
    </tr>

    <tr>
      <td>
        reasoning
      </td>

      <td>
        Boolean
      </td>

      <td>
        No
      </td>

      <td>
        False
      </td>

      <td>
        Reasoning engine that improves translation quality
      </td>
    </tr>

    <tr>
      <td>
        reasoningEffort
      </td>

      <td>
        String
      </td>

      <td>
        No
      </td>

      <td>
        `high`
      </td>

      <td>
        Defines the reasoning effort level. Available options: `low`, `medium`, `high`.
      </td>
    </tr>

    <tr>
      <td>
        imageContext
      </td>

      <td>
        ImageSchema
      </td>

      <td>
        No
      </td>

      <td>
        -
      </td>

      <td>
        Optional image providing visual context for translation. Accepts an HTTPS URL or base64 data URL. Requires `reasoning: true`
      </td>
    </tr>

    <tr>
      <td>
        styleguideId
      </td>

      <td>
        Integer
      </td>

      <td>
        No
      </td>

      <td>
        -
      </td>

      <td>
        The ID of the style guide that will be used by Lara Prosa
      </td>
    </tr>

    <tr>
      <td>
        styleguideReasoning
      </td>

      <td>
        Boolean
      </td>

      <td>
        No
      </td>

      <td>
        False
      </td>

      <td>
        If set to `true`, Lara Prosa will be active in reasoning mode
      </td>
    </tr>

    <tr>
      <td>
        styleguideExplanationLanguage
      </td>

      <td>
        String
      </td>

      <td>
        No
      </td>

      <td>
        en
      </td>

      <td>
        The language of the comments regarding the changes to the translation by Lara Prosa
      </td>
    </tr>

    <tr>
      <td>
        profanitiesDetect
      </td>

      <td>
        String
      </td>

      <td>
        No
      </td>

      <td>
        -
      </td>

      <td>
        defines the scope of the profanity filtering.<br />Available options:  `source_target ` `target`
      </td>
    </tr>

    <tr>
      <td>
        profanitiesHandling
      </td>

      <td>
        String
      </td>

      <td>
        No
      </td>

      <td>
        `hide`
      </td>

      <td>
        Specifies how Lara handles profanity in the translation.<br />Available options: `detect` `hide` `avoid`
      </td>
    </tr>

    <tr>
      <td>
        style
      </td>

      <td>
        String
      </td>

      <td>
        No
      </td>

      <td>
        `faithful`
      </td>

      <td>
        The style to apply to the translation. Available values: `faithful` `fluid` `creative`
      </td>
    </tr>

    <tr>
      <td>
        content_type
      </td>

      <td>
        String
      </td>

      <td>
        No
      </td>

      <td>
        Autodetected
      </td>

      <td>
        Specifies the `Content-Type` of the text. Available values: `text/plain`<br />`text/html`<br />`application/xliff+xml`
      </td>
    </tr>

    <tr>
      <td>
        timeout_ms
      </td>

      <td>
        Integer
      </td>

      <td>
        No
      </td>

      <td>
        None
      </td>

      <td>
        Specifies the maximum allowable time (in milliseconds) to perform the translation. If the timeout is exceeded, a `TimeoutException` is raised.
      </td>
    </tr>

    <tr>
      <td>
        priority
      </td>

      <td>
        String
      </td>

      <td>
        No
      </td>

      <td>
        Normal
      </td>

      <td>
        Specifies whether the translation should be executed as a normal priority task or can wait for other tasks to complete.
      </td>
    </tr>

    <tr>
      <td>
        use_cache
      </td>

      <td>
        Boolean
      </td>

      <td>
        No
      </td>

      <td>
        False
      </td>

      <td>
        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](https://laratranslate.com/sales)

        .
      </td>
    </tr>

    <tr>
      <td>
        cache_ttl
      </td>

      <td>
        Integer
      </td>

      <td>
        No
      </td>

      <td>
        2 Years
      </td>

      <td>
        The time-to-live (TTL) for the cache entry, specifying how long the translation will remain in the cache.
      </td>
    </tr>

    <tr>
      <td>
        verbose
      </td>

      <td>
        Boolean
      </td>

      <td>
        No
      </td>

      <td>
        False
      </td>

      <td>
        When 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.
      </td>
    </tr>

    <tr>
      <td>
        headers
      </td>

      <td>
        List\[String,  String]
      </td>

      <td>
        No
      </td>

      <td>
        None
      </td>

      <td>
        An 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.
      </td>
    </tr>

    <tr>
      <td>
        no_trace<br />_(see the snippet below for the correct syntax)_
      </td>

      <td>
        Boolean
      </td>

      <td>
        No
      </td>

      <td>
        False
      </td>

      <td>
        If set to True, source content and its translation will not be saved on our system. (AKA Incognito mode)
      </td>
    </tr>
  </tbody>
</Table>

### Incognito mode

```python
res = lara.translate('Hello, how are you?',
    source='en-US',
    target='it-IT',
   	noTrace = true
    )

print(res.translation)
```
```typescript
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'],
        no_trace: true
});
```
```java
// 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.setNoTrace(true);

TextResult res = lara.translate("Hello, how are you?", "en-US", "it-IT", options);
```
```php
$options = new TranslateOptions([
    'adaptTo' => array('mem_1_id', 'mem_2_id'),
     'glossaries' => array('gls_1_id', 'gls_2_id'),
	  'noTrace' => true,
]);

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

fmt.Println(*res.Translation.String)
```
```kotlin
// 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")
    setNoTrace(true)
}

val res: TextResult = lara.translate(
    "Hello, how are you?",
    "en-US",
    "it-IT",
    options
)
```
```csharp
var res = await lara.Translate(
    "test example", "en-US", "it-IT",
new TranslateOptions {
    Instructions = new[] { "Be formal" },
    Style = TranslationStyle.Fluid,
    NoTrace = true
});
```
```swift
// 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"])
    .setNoTrace(true)
    

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

### Image context with Lara Think

```python
import base64
from pathlib import Path
from lara_sdk import Translator, Credentials, ImageContext

LARA_ACCESS_KEY_ID = "your-access-key-id"
LARA_ACCESS_KEY_SECRET = "your-access-key-secret"

# Initialization of the Translator class
credentials = Credentials(access_key_id=LARA_ACCESS_KEY_ID, access_key_secret=LARA_ACCESS_KEY_SECRET)
lara = Translator(credentials)

#direct HTTPS URL:
https_image = ImageContext(
    url="https://example.com/image.png"
)

# Or you can use a local image converted to Base64
image_path = Path("screenshot.png")
base64_image = ImageContext(
    url="data:image/png;base64," + base64.b64encode(image_path.read_bytes()).decode("ascii")
)

res = lara.translate(
    text="Submit",           # The ambiguous text to translate
    source="en-US",
    target="it-IT",
    reasoning=True,          # Mandatory: enable Lara Think
    reasoningEffort="high",  # Optional: set the reasoning effort level (low, medium, high)
    imageContext=base64_image, # Pass the image to provide visual context for the translation
    content_type="text/plain"
)

print(res.translation)
```
```typescript
import { readFileSync } from "node:fs";
import type { ImageContext, Credentials, Translator} from "@translated/lara";

const LARA_ACCESS_KEY_ID: string = "your-access-key-id";
const LARA_ACCESS_KEY_SECRET: string = "your-access-key-secret";

const credentials = new Credentials(LARA_ACCESS_KEY_ID, LARA_ACCESS_KEY_SECRET)
const lara: Translator = new Translator(credentials);
// Create the ImageContext object
// Example reading a local file in Base64:
const base64Image: ImageContext = {
  url: `data:image/png;base64,${readFileSync("screenshot.png").toString("base64")}`
};

// Example using an HTTPS URL:
// const httpsImage: ImageContext = { url: "https://example.com/screenshot.png" };

// Execute the translation with Lara Think
async function translateWithContext() {
  const res = await lara.translate(
    "Submit", 
    "en-US", 
    "it-IT", 
    {
      reasoning: true,            // Mandatory: enable Lara Think
      reasoningEffort: "high",    // Optional: reasoning effort
      imageContext: base64Image,  // The visual context
      contentType: "text/plain"
    }
  );

  console.log(res.translation);
}

translateWithContext();
```
```java
import com.translated.lara.translator.Lara;
import com.translated.lara.translator.ImageContext;
import com.translated.lara.translator.TranslateOptions;
import com.translated.lara.translator.TextResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;

public class LaraExample {
        public static void main(String[] args) throws Exception {
        // Initialize the client
        private static final String LARA_ACCESS_KEY_ID = "your-access-key-id";
        private static final String LARA_ACCESS_KEY_SECRET = "your-access-key-secret";

        Credentials credentials = new Credentials(LARA_ACCESS_KEY_ID,      LARA_ACCESS_KEY_SECRET);
        Translator lara = new Translator(credentials);

        // Create the ImageContext object
        // Example using an HTTPS URL:
        // ImageContext httpsImage = new ImageContext("https://example.com/screenshot.png");
        
        // Example reading a local file in Base64:
        ImageContext base64Image = new ImageContext(
            "data:image/png;base64," + Base64.getEncoder().encodeToString(Files.readAllBytes(Path.of("screenshot.png")))
        );

        // Execute the translation with Lara Think
        TranslateOptions options = new TranslateOptions();
        options.setReasoning(true);               // Mandatory: enable Lara Think
        options.setReasoningEffort("high");       // Optional: set the reasoning effort level
        options.setImageContext(base64Image);     // Pass the image to provide visual context
        options.setContentType("text/plain");

        TextResult res = lara.translate("Submit", "en-US", "it-IT", options);
        System.out.println(res.getTranslation());
    }
}
```
```php
require 'vendor/autoload.php';

use Lara\Lara;
use Lara\ImageContext;
use Lara\Translator;
use Lara\LaraCredentials;

$LARA_ACCESS_KEY_ID = "your-access-key-id";
$LARA_ACCESS_KEY_SECRET = "your-access-key-secret";

// Initialization of the Translator class
$credentials = new LaraCredentials($LARA_ACCESS_KEY_ID, $LARA_ACCESS_KEY_SECRET);
$lara = new Translator($credentials);

// Create the ImageContext object
// Example using an HTTPS URL:
// $httpsImage = new ImageContext('https://example.com/screenshot.png');

// Example reading a local file in Base64:
$base64Image = new ImageContext(
    'data:image/png;base64,' . base64_encode(file_get_contents('screenshot.png'))
);

// Execute the translation with Lara Think
$options = new TranslateOptions([
    'reasoning' => true,             // Mandatory: enable Lara Think
    'reasoningEffort' => 'high',     // Optional: set the reasoning effort level
    'imageContext' => $base64Image,  // The visual context
    'contentType' => 'text/plain'
]);

$res = $lara->translate('Submit', 'en-US', 'it-IT', $options);
echo $res->translation;
```
```go
package main

import (
	"encoding/base64"
	"fmt"
	"os"
	"github.com/translated/lara-go" // Ensure you use the correct Lara SDK import path
)

const (LARA_ACCESS_KEY_ID     = "your-access-key-id"
	LARA_ACCESS_KEY_SECRET = "your-access-key-secret")

credentials := lara_sdk.NewCredentials(LARA_ACCESS_KEY_ID, LARA_ACCESS_KEY_SECRET)
lara := lara_sdk.NewTranslator(credentials, nil)

data, err := os.ReadFile("screenshot.png")
	if err != nil {
		panic(err)
	}

	// Example reading a local file in Base64:
	base64Image := lara.ImageContext{
		URL: "data:image/png;base64," + base64.StdEncoding.EncodeToString(data),
	}

	// Execute the translation with Lara Think
	options := lara.TranslateOptions{
		Reasoning:       true,         // Mandatory: enable Lara Think
		ReasoningEffort: "high",       // Optional: set the reasoning effort level
		ImageContext:    &base64Image, // Pass the image for visual context
		ContentType:     "text/plain",
	}

	res, err := client.Translate("Submit", "en-US", "it-IT", options)
	if err != nil {
		panic(err)
	}

	fmt.Println(*res.Translation.String)

```
```kotlin
import com.translated.lara.translator.ImageContext
import com.translated.lara.Credentials
import com.translated.lara.translator.Translator
import java.io.File
import java.util.Base64

private const val LARA_ACCESS_KEY_ID = "your-access-key-id"
private const val LARA_ACCESS_KEY_SECRET = "your-access-key-secret"

// Initialization of the Translator class
val credentials = Credentials(LARA_ACCESS_KEY_ID, LARA_ACCESS_KEY_SECRET)
val lara = Translator(credentials)

// Create the ImageContext object
// Example using an HTTPS URL:
// val httpsImage = ImageContext("https://example.com/screenshot.png")
    
// Example reading a local file in Base64:
val base64Image = ImageContext("data:image/png;base64," + Base64.getEncoder().encodeToString(File("screenshot.png").readBytes()))

// Execute the translation with Lara Think
 val options = TranslateOptions().apply {
        setReasoning(true)               // Mandatory: enable Lara Think
        setReasoningEffort("high")       // Optional: reasoning effort
        setImageContext(base64Image)     // The visual context
        setContentType("text/plain")
    }

 val res: TextResult = lara.translate("Submit", "en-US", "it-IT", options)
 println(res.translation)
```
```csharp
using System;
using System.IO;
using Lara.Sdk;
using System.Threading.Tasks;

string accessKeyId = "your-access-key-id";
string accessKeySecret = "your-access-key-secret";

var credentials = new Credentials(accessKeyId, accessKeySecret);
var lara = new Translator(credentials);

// Initialize the client
        var lara = new LaraClient(Environment.GetEnvironmentVariable("LARA_API_KEY"));

// Create the ImageContext object
// Example using an HTTPS URL:
// var httpsImage = new ImageContext("https://example.com/screenshot.png");

// Example reading a local file in Base64:
var base64Image = new ImageContext("data:image/png;base64," + Convert.ToBase64String(File.ReadAllBytes("screenshot.png"))
        );

// Execute the translation with Lara Think
var options = new TranslateOptions
{
  Reasoning = true,               // Mandatory: enable Lara Think
  ReasoningEffort = "high",       // Optional: reasoning effort level
  ImageContext = base64Image,     // Visual context
  ContentType = "text/plain"
 };

 var res = await lara.Translate("Submit", "en-US", "it-IT", options);
 Console.WriteLine(res.Translation);
```
```swift
import Foundation
import Lara

let LARA_ACCESS_KEY_ID = "your-access-key-id"
let LARA_ACCESS_KEY_SECRET = "your-access-key-secret"

// Initialization of the Translator class
let credentials = Credentials(accessKeyId: LARA_ACCESS_KEY_ID, accessKeySecret: LARA_ACCESS_KEY_SECRET)
let lara = Translator(credentials: credentials)

// Initialize the client
  let apiKey = ProcessInfo.processInfo.environment["LARA_API_KEY"] ?? ""
  let lara = Lara(apiKey: apiKey)

// Create the ImageContext object
// Example using an HTTPS URL:
// let httpsImage = ImageContext(url: "https://example.com/screenshot.png")

// Example reading a local file in Base64:
  let encoded = try Data(contentsOf: URL(fileURLWithPath:"screenshot.png")).base64EncodedString()
let base64Image = ImageContext(url: "data:image/png;base64,\(encoded)")

// Execute the translation with Lara Think
  let options = TranslateOptions()
        .setReasoning(true)              // Mandatory: enable Lara Think
        .setReasoningEffort("high")      // Optional: set the reasoning effort level
        .setImageContext(base64Image)    // Pass the image for visual context
        .setContentType("text/plain")

  do {
  let res = try await lara.translate(
            text: "Submit", 
            source: "en-US", 
            target: "it-IT", 
            options: options
        )
        print(res.translation)
    } catch {
        print("Translation failed: \(error)")
    }
```

### Response

```python
# 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)
    ]
)
```
```typescript
// 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']
}
```
```java
// 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)
    ]
)
```
```php
// 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']
}
```
```go
// 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"},
}

```
```kotlin
// 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)
    )
)
```
```csharp
// 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)
    }
)
```
```swift
// 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"]
)
```

<Callout icon="❗️" theme="error">
  ### 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](https://developers.laratranslate.com/docs/translate-document) service.
</Callout>

## Lara Prosa

Lara Prosa is an advanced stylistic translation service for high-value content where voice, rhythm, and editorial quality matter as much as accuracy.

It builds on Lara’s core translation capabilities by combining glossaries, translation memories, and style guides to preserve meaning, terminology, consistency, and authorial or brand voice.

Rather than producing only fluent translations, Lara Prosa refines the text to maintain the distinctive nuances, personality, and expressive choices of the original. Alongside the translated output, it also provides structured editorial notes that explain key stylistic decisions.

Lara Prosa is designed for literary content, author-driven material, premium editorial workflows, and brand-sensitive communication where stylistic fidelity is essential.

**Availability & Pricing**

Lara Prosa is available on the plans below. Pricing is calculated per one million source characters.

| Plan | Standard      | With reasoning |
| ---- | ------------- | -------------- |
| Free | Not Available | Not Available  |
| Pro  | € 200\*       | € 400\*        |
| Team | € 150\*       | € 300\*        |

*\*Pricing per 1M characters*

To use Lara Prosa, simply pass the `styleguideId` parameter with the ID of the style guide you want to use. If you want higher quality, you can activate the `styleguideReasoning:true` parameter.

```python
res = lara.translate('Hello, how are you?',
                     source='en-US',
                     target='it-IT',
                     styleguideId=123456,
                     styleguideReasoning=True
                     )

print(res.translation)
```
```typescript
const res  = await lara.translate('Hello, how are you?', 'en-US', 'it-IT', {
        styleguideReasoning: true,
        styleguideId=123456
});
```
```java
TranslateOptions options = new TranslateOptions();
options.setStyle(TranslationStyle.FLUID);
options.setReasoning(true);

TextResult res = lara.translate("Hello, how are you?", "en-US", "it-IT", options);
```
```php
$options = new TranslateOptions([
	'styleguideReasoning':true,
  'styleguideId'=123456
]);

$res = $lara->translate('Hello, how are you?', 'en-US', 'it-IT', $options);
```
```go Go
res, _ := lara.Translate("Hello, how are you?", "en-US", "it-IT",
	lara_sdk.TranslateOptions{
		StyleguideReasoning:  true,
		StyleguideId:    123456
  })

fmt.Println(*res.Translation.String)
```
```kotlin
// Sdk available soon
```
```csharp
var res = await lara.Translate(
    "test example", "en-US", "it-IT",
new TranslateOptions {
  	styleguideReasoning = true,
		styleguideId = 123456,
});
```
```swift
// All options are optional and can be omitted
let options = TranslateOptions()
    .setAdaptTo(["mem_1_id", "mem_2_id"])
    .setStyleguideId(123456)
		.setStyleguideReasoning(true)
	  
let res = try await lara.translate(text: "Hello, how are you?", source: "en-US", target: "it-IT", options: options)
```

<Callout icon="📘" theme="info">
  ### Create your style guide

  [Here](https://developers.laratranslate.com/docs/manage-style-guide) you can find all the information you need to create and manage your style guides
</Callout>

## 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.

| Plan | High Reasoning Effort                    | Medium Reasoning Effort              | Low Reasoning Effort               |
| ---- | ---------------------------------------- | ------------------------------------ | ---------------------------------- |
| Free | Not Available                            | Not Available                        | Not Available                      |
| Pro  | €2,000 / 1M chars<br />$2,499 / 1M chars | €500 / 1M chars<br />$625 / 1M chars | €50 / 1M chars<br />$62 / 1M chars |
| Team | €1,500 / 1M chars<br />$1,999 / 1M chars | €400 / 1M chars<br />$533 / 1M chars | €40 / 1M chars<br />$53 / 1M chars |

### 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.

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

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

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

$res = $lara->translate('Hello, how are you?', 'en-US', 'it-IT', $options);
```
```go Go
// Sdk available soon
```
```kotlin
// Sdk available soon
```
```csharp
var res = await lara.Translate(
    "test example", "en-US", "it-IT",
new TranslateOptions {
     Reasoning = true,
     Style = TranslationStyle.Fluid,
});
```
```swift
// 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.

```python
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)
```
```typescript
const res  = await lara.translate('Hello, how are you?', 'en-US', 'it-IT', {
        reasoning:true,
        style: 'fluid',
}, (partialResult) => console.log(partialResult)
);
```
```java
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);
```
```php
$lara->translate(
    "Please summarize the following: Lara translates text.",
    $source, $target,
    new TranslateOptions([
        'reasoning' => true,
        'style' => 'fluid'
    ]),
    function ($partial) {
        print_r($partial);
    }
);;
```
```go
// Sdk available soon
```
```kotlin
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)
```
```csharp
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) 
);
```
```swift
// 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.<br />`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`).

## Do Not Translate *(DNT tags)*

To ensure maximum translation accuracy, Lara supports the exclusion of specific text segments. When the translation engine encounters a DNT tag, the content enclosed within it will be preserved in its entirety, without undergoing any translation, localization, or capitalization changes.

#### **Web Standards *(Recommended)***

These tags are the standard for the web and ensure maximum compatibility with crawlers and localization systems:

* **HTML5 attribute (W3C standard):**<br />Use the attribute `translate="no"` on any HTML tag.<br />*Example:*`<p translate="no">`*BrandName*`</p>`*&#x20;or&#x20;*`<div translate="no">`*Confidential text*`</div>`
* **Legacy CSS class:**<br />Support for the .notranslate class.<br />*Example:*`<span class="notranslate">`*text not to be translated*`</span>`

*Note: The attribute translate="no" and the class notranslate are recognized on every type of HTML element (e.g.&#x20;*`<div>`*,&#x20;*`<p>`*,&#x20;*`<a>`*, etc.) and are not limited to the \<span> tag only.*

#### **Custom Tag (XML/HTML)**

For specific contexts or custom formats, you can use the dedicated custom tag:

* **XML/HTML tag:&#x20;**`<notranslate>`*&#x20;ProductCode123&#x20;*`</notranslate>`

<Callout icon="⚠️" theme="warn">
  ### **Important notes**

  **Limitations of the Plain Text format:** Please note that this feature **is not available** when the input content is sent as text/plain. To enable tag recognition, make sure the input format is correctly set to text/html.
</Callout>

**Summary Table:** It might be useful to add a summary table for developers who need a quick reference:

| Syntax                | Type         | Example                                |
| :-------------------- | :----------- | :------------------------------------- |
| `translate="no"`      | W3C Standard | `<span translate="no">`...`</span>`    |
| `class="notranslate"` | Web Legacy   | `<div class="notranslate">`...`</div>` |
| `<notranslate>`       | Custom       | `<notranslate>`ID\_001`</notranslate>` |