Translate Image
Translator
The Translator class is the core component of the lara-sdk, designed for translating text. It must be initialized with authentication credentials.
from lara_sdk import Translator, Credentials
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)import {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";
// Initialization of the Translator class
const credentials = new Credentials(LARA_ACCESS_KEY_ID, LARA_ACCESS_KEY_SECRET)
const lara: Translator = new Translator(credentials);import com.translated.lara.Credentials;
import com.translated.lara.translator.Translator;
private static final String LARA_ACCESS_KEY_ID = "your-access-key-id";
private static final String LARA_ACCESS_KEY_SECRET = "your-access-key-secret";
// Initialization of the Translator class
Credentials credentials = new Credentials(LARA_ACCESS_KEY_ID, LARA_ACCESS_KEY_SECRET);
Translator lara = new Translator(credentials);<?php
require 'vendor/autoload.php';
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);import (
lara_sdk "github.com/translated/lara-go/lara" // alias "lara_sdk", can be changed or removed
)
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)
import com.translated.lara.Credentials
import com.translated.lara.translator.Translator
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)string accessKeyId = "your-access-key-id";
string accessKeySecret = "your-access-key-secret";
var credentials = new Credentials(accessKeyId, accessKeySecret);
var lara = new Translator(credentials);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)Translate
Translates image from a source language to a target language. It supports context-aware translations and adaptation to specific translation memories, it returns a translated image.
Request
sample_image_path = "sample_image.png"
translated_image = lara.images.translate(
source="en-US",
target="fr-FR",
image_path=sample_image_path,
text_removal="overlay"
)const res = await lara.images.translate('path/to/image.jpg', 'en-US', 'it-IT', {
adaptTo: ['mem_1_id', 'mem_2_id'],
glossaries: ['gls_1_id', 'gls_2_id'],
instructions: ['Be formal'],
style: 'fluid'
});File imageFile = new File("image.jpg");
ImageTranslateOptions options = new ImageTranslateOptions();
options.setAdaptTo("mem_1234...");
options.setGlossaries("gls_1234...");
options.setTextRemoval(ImageTextRemoval.OVERLAY);
InputStream translated = lara.images.translate(imageFile, "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);// Sdk available soon
// Sdk available soon
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,
});
// Sdk available soon
Here follows the basic fields for the translate method:
Field | Type | Required | Default | Description |
|---|---|---|---|---|
file / imagePath | File / String | Yes | The input image/the path to input image to translate. | |
source | String | No | Autodetected | The source language code (e.g., "en-EN" for English). If not specified, the system will attempt to detect it automatically. |
target | String | Yes | The target language code (e.g., "it-IT" for Italian). This specifies the language you want the text translated into. | |
options | ImageTranslationOptions | No | See the table below for details. |
Several options are available to customize the behavior of the translate method:
Field | Type | Required | Default | Description |
|---|---|---|---|---|
adaptTo | String[] | No | Default is all Memories on your account | A list of translation memory IDs for adapting the translation. |
glossaries | String[] | No | A list of glossary IDs. | |
noTrace | Boolean | No | False | If set to True, source content and its translation will not be saved on our system. (AKA Incognito mode) |
style | String | No |
| The style to apply to the translation. Available values:
|
textRemoval | String | No |
| Customize how the original text is removed from the image. |
Translate text image
Translates the text inside an image from a source language to a target language. It supports context-aware translations and adaptation to specific translation memories, it returns the original and the translated text.
Request
sample_image_path = "sample_image.png"
text_results = lara.images.translate_text(
source="en-US",
target="es-ES",
image_path=sample_image_path
)const res = await lara.images.translateText('path/to/image.jpg', 'en-US', 'it-IT', {
adaptTo: ['mem_1_id', 'mem_2_id'],
glossaries: ['gls_1_id', 'gls_2_id'],
style: 'fluid'
});File imageFile = new File("image.jpg");
ImageTextTranslateOptions options = new ImageTextTranslateOptions();
options.setAdaptTo("mem_1234...");
options.setGlossaries("gls_1234...");
ImageTextResult result = lara.images.translateText(imageFile, "en-US", "it-IT", options);// Sdk available soon
// Sdk available soon
// Sdk available soon
// Sdk available soon
// Sdk available soon
Here follows the basic fields for the translateText method:
Field | Type | Required | Default | Description |
|---|---|---|---|---|
file / imagePath | File / String | Yes | The input image/the path to input image to translate. | |
source | String | No | Autodetected | The source language code (e.g., "en-EN" for English). If not specified, the system will attempt to detect it automatically. |
target | String | Yes | The target language code (e.g., "it-IT" for Italian). This specifies the language you want the text translated into. | |
options | ImageTextTranslationOptions | No | See the table below for details. |
Several options are available to customize the behavior of the translateText method:
Field | Type | Required | Default | Description |
|---|---|---|---|---|
adaptTo | String[] | No | Default is all Memories on your account | A list of translation memory IDs for adapting the translation. |
glossaries | String[] | No | A list of glossary IDs. | |
noTrace | Boolean | No | False | If set to True, source content and its translation will not be saved on our system. (AKA Incognito mode) |
style | String | No |
| The style to apply to the translation. Available values:
|
Response
// Sdk available soon
TextResult(
translation=[
Paragraphs(text="Hello, how are you?",translation = "Ciao, come stai?"),
Paragraphs(text="What a wonderful day",translation = "Che giornata meravigliosa.")
]
)// Sdk available soon
// Sdk available soon
// Sdk available soon
// Sdk available soon
// Sdk available soon
// Sdk available soon
Supported languages
Billing
Details are available in the pricing page
Updated 6 days ago
