Manage Translation Memories

Translation memory Management

Translation Memories are tools that save previously translated text segments, such as sentences or paragraphs. Each saved segment includes the 'source' text and its translated 'target' text, forming pairs known as translation units (TUs). These translation memories connect with Lara via specific APIs, and you can find instructions on how to add and update them in this section of the API documentation. Lara's adaptive version significantly outperforms the static version, ensuring more effective and efficient translations.

All memories functionalities can be accessed via the same Translator (lara in the example) object created to translate.

Memory object

FieldTypeDescription
idStringUnique ID of the memory. Format: mem_xyz123
secretStringUnique Secret of the memory, used for sharing feature
nameStringCustom name of the memory, it can be any string including spaces and special characters and non-latin alphabets. Max length: 250 characters.
created_atDateTimeWhen the memory is created
updated_atDateTimeWhen the memory is last updated (equal to created_at with no updates)
owner_idStringUser who owns the memory. Format: acc_123xyz
shared_atDateTimeWhen the memory is last shared (equal to created_at if never shared)
collaborators_countIntegerNumber of users who can access this memory to retrieve TU

List Memories

Lists all memories available to the user

# List all memories available to the user
memories = lara.memories.list()
// List all memories available to the user
const memories = await lara.memories.list();
// List all memories available to the user
List<Memory> memories = lara.memories.list();
// List all memories available to the user
$memories = $lara->memories->getAll();
// List all memories available to the user
memories, _ := lara.Memories.List()
// List all memories available to the user
val memories: List<Memory> = lara.memories.list()
// List all memories available to the user
var memories = await lara.Memories.List();
// List all memories available to the user
let memories = try await lara.memories.list()

Create new Memory

Creates a new memory with a custom name.
It is also possible to import a memory from MyMemory using as external_id the id of the memory on MyMemory

# Create a new empty memory with name 'Memory 1'
memory = lara.memories.create('Memory 1')

# Create a new memory with name 'Memory from MyMemory' using the content of the memory on MyMemory (with id aabb1122)
memory_2 = lara.memories.create('Memory from MyMemory', 'aabb1122')
// Create a new empty memory with name 'Memory 1'
const memory = await lara.memories.create('Memory 1');

// Create a new memory with name 'Memory from MyMemory' using the content of the memory on MyMemory (with id aabb1122)
const memory2 = await lara.memories.create('Memory from MyMemory', 'aabb1122');
// Create a new empty memory with name 'Memory 1'
Memory memory = lara.memories.create("Memory 1");

// Create a new memory with name 'Memory from MyMemory' using the content of the memory on MyMemory (with id aabb1122)
Memory memory2 = lara.memories.create("Memory from MyMemory", "aabb1122");
// Create a new empty memory with name 'Memory 1'
$memory = $lara->memories->create('Memory 1');

// Create a new memory with name 'Memory from MyMemory' using the content of the memory on MyMemory (with id aabb1122)
$memory2 = $lara->memories->create('Memory from MyMemory', 'aabb1122');
// Create a new empty memory with name 'Memory 1'
memory, _ := lara.Memories.Create("Memory 1")

// Create a new memory with name 'Memory from MyMemory' using the content of the memory on MyMemory (with id aabb1122)
memory2, _ := lara.Memories.CreateWithExternalID("Memory from MyMemory", "ext_my_aabb1122")
// Create a new empty memory with name "Memory 1"
val memory: Memory = lara.memories.create("Memory 1")

// Create a new memory with name "Memory from MyMemory" using the content of the memory with id "aabb1122"
val memory2: Memory = lara.memories.create("Memory from MyMemory", "aabb1122")
// Create a new empty memory with name 'Memory 1'
var memory = await lara.Memories.Create("Memory 1");

// Create a new memory with name 'Memory from MyMemory' using the content of the memory on MyMemory (with id aabb1122)
var memory2 = await lara.Memories.Create("Memory from MyMemory", "ext_my_aabb1122");
// Create a new empty memory with name 'Memory 1'
let memory = try await lara.memories.create(name: "Memory 1")

// Create a new memory with name 'Memory from MyMemory' using the content of the memory on MyMemory (with id aabb1122)
let memory2 = try await lara.memories.create(name: "Memory from MyMemory", externalId: "ext_my_aabb1122")
FieldTypeRequiredDefaultDescription
nameStringYes

The name of the new memory
external_idStringNo

The ID of the memory to be imported from MyMemory. Use this to initialize the memory with external content.
Format: extmy[MyMemory ID]

Update Memory Name

Updates the name of a specific memory

# Update memory name
updated_memory = lara.memories.update('mem_1...', 'New Name for my memory')
// Update memory name
const updatedMemory = await lara.memories.update('mem_1...', 'New Name for my memory');
// Update memory name
Memory updatedMemory = lara.memories.update("mem_1...", "New Name for my memory");
// Update memory name
$updatedMemory = $lara->memories->update('mem_1...', 'New Name for my memory');
// Update memory name
updatedMemory, _ := lara.Memories.Update("mem_1...", "New Name for my memory")
// Update memory name
val updatedMemory: Memory = lara.memories.update("mem_1...", "New Name for my memory")
// Update memory name
var updatedMemory = await lara.Memories.Update("mem_1...", "New Name for my memory");
// Update memory name
let updatedMemory = try await lara.memories.update(id: "mem_1...", name: "New Name for my memory")
FieldTypeRequiredDefaultDescription
idStringYes

The unique identifier of the memory to update.
Format: mem_xyz123
nameStringYes

The new name for the memory

Delete Memory

Deletes a specific memory

# Delete a memory
deleted_memory = lara.memories.delete('mem_1...')
// Delete a memory
const deletedMemory = await lara.memories.delete('mem_1...');
// Delete a memory
Memory deletedMemory = lara.memories.delete("mem_1...");
// Delete a memory
$deletedMemory = $lara->memories->delete('mem_1...');
// Delete a memory
deletedMemory, _ := lara.Memories.Delete("mem_1...")
// Delete a memory
val deletedMemory: Memory = lara.memories.delete("mem_1...")
// Delete a memory
var deletedMemory = await lara.Memories.Delete("mem_1...");
// Delete a memory
let deletedMemory = try await lara.memories.delete(id: "mem_1...")
FieldTypeRequiredDefaultDescription
idStringYes

The unique identifier of the memory to update.
Format: mem_xyz123

Import TMX to Memory

Imports a TMX file into an existing memory

# Import a local tmx file to an existing memory
import_job = lara.memories.import_tmx('mem_1...', 'file/to/path')
/*
	NODE
*/
import * as fs from 'fs';

// Import a local tmx file to an existing memory
const stream = fs.createReadStream('path/to/tmx');
const importJob = await lara.memories.importTmx('mem_1...', stream);

// Import a local compressed tmx file to an existing memory
const streamGzip = fs.createReadStream('path/to/tmx.gz');
const importJobGzip = await lara.memories.importTmx('mem_1...', streamGzip, true)

/*
	BROWSER
*/
// replace with your input id
const fileInput = document.getElementById("fileInput");
const file = fileInput.files[0];

const importJob = await lara.memories.importTmx(MEMORY_ID, file, true/false);
// Import a local tmx file to an existing memory
MemoryImport importJob = lara.memories.importTmx("mem_1...", new File("file/to/path"));
// Import a local tmx file to an existing memory
$importJob = $lara->memories->importTmx('mem_1...', 'file/to/path');
// Import a local tmx file to an existing memory
importResult, _ := lara.Memories.ImportTmxFromPath("mem_1...", "file/to/path")
// Import a local tmx file to an existing memory
val importJob: MemoryImport = lara.memories.importTmx("mem_1...", File("file/to/path"))
// Import a local tmx file to an existing memory
var importResult = await lara.Memories.ImportTmx("mem_1...", "path/to/file");
// Import a local tmx file to an existing memory
let tmxURL = URL(fileURLWithPath: "path/to/file.tmx")
let tmxData = try Data(contentsOf: tmxURL)
let importJob = try await lara.memories.importTmx(id: "mem_1...", tmx: tmxData)
FieldTypeRequiredDefaultDescription
idStringYes

The unique identifier of the memory to update.
Format: mem_xyz123
tmxFile |
Stream |
String
Yes

The tmx file to upload
gzipBooleanNoFalseIndicates if the file is a compressed .gz file.
Not present for Python and Java, where it is automatically detected

Check Import Status

Checks the status of an ongoing memory import using the unique import_job id returned in the "Import TMX" method

# Get the import status
import_job = lara.memories.get_import_status('imp_1...')
// Get the import status
const importJob = await lara.memories.getImportStatus('imp_1...');
// Get the import status
MemoryImport importJob = lara.memories.getImportStatus("imp_1...");
// Get the import status
$importJob = $lara->memories->getImportStatus('imp_1...');
// Get the import status
importResult, _ := lara.Memories.GetImportStatus("imp_1...")
// Get the import status
val importJob: MemoryImport = lara.memories.getImportStatus("imp_1...")
// Get the import status
var importResult = await lara.Memories.GetImportStatus("imp_1...");
// Get the import status
let importJob = try await lara.memories.getImportStatus(id: "imp_1...")
FieldTypeRequiredDescriptionDefault
idStringYesThe ID of the import job


Add Translation (TU) to Memory

Add a translation unit to a memory. Context information and unique ID can be specified

# Add a simple translation unit to an existing memory
import_job = lara.memories.add_translation(
    'mem_1...',
    source='en-US',
    target='it-IT',
    sentence='Hello World!',
    translation='Ciao Mondo!'
)

# Add a simple translation unit to multiple existing memories
multi_import_job = lara.memories.add_translation(
    ['mem_1...', 'mem_2...'],
    source='en-US',
    target='it-IT',
    sentence='Hello World!',
    translation='Ciao Mondo!'
)
// Add a simple translation unit to an existing memory
const importJob = await lara.memories.addTranslation(
    'mem_1...',
    'en-US',
    'it-IT',
    'Hello World!',
    'Ciao Mondo!'
);

// Add a simple translation unit to multiple existing memories
const multiImportJob = await lara.memories.addTranslation(
    ['mem_1...', 'mem_2...'], 
    'en-US', 
    'it-IT', 
    'Hello World!', 
    'Ciao Mondo!'
);
// Add a simple translation unit to an existing memory
MemoryImport importJob = lara.memories.addTranslation(
        "mem_1...", 
        "en-US", 
        "it-IT", 
        "Hello World!", 
        "Ciao Mondo!"
);

// Add a simple translation unit to multiple existing memories
MemoryImport multiImportJob = lara.memories.addTranslation(
        Arrays.asList("mem_1...", "mem_2..."), 
        "en-US", 
        "it-IT", 
        "Hello World!", 
        "Ciao Mondo!"
);
// Add a simple translation unit to an existing memory
$importJob = $lara->memories->addTranslation(
    'mem_1...',
    'en-US',
    'it-IT',
    'Hello World!',
    'Ciao Mondo!'
);

// Add a simple translation unit to multiple existing memories
$multiImportJob = $lara->memories->addTranslation(
    array('mem_1...', 'mem_2...'),
    'en-US',
    'it-IT',
    'Hello World!',
    'Ciao Mondo!'
);
// Add a simple translation unit to an existing memory
importJob, _ := lara.Memories.AddTranslation(
	"mem_1...",
	"en-US",
	"it-IT",
	"Hello World!",
	"Ciao Mondo!",
)

// Add a simple translation unit to multiple existing memories
multiAddResult, err := lara.Memories.AddTranslationMultiple(
	[]string{"mem_1...", "mem_2..."},
	"en-US",
	"it-IT",
	"Hello World!",
	"Ciao Mondo!",
)
// Add a simple translation unit to an existing memory
val importJob: MemoryImport = lara.memories.addTranslation(
    "mem_1...",
    "en-US",
    "it-IT",
    "Hello World!",
    "Ciao Mondo!"
)

// Add a simple translation unit to multiple existing memories
val multiImportJob: MemoryImport = lara.memories.addTranslation(
    listOf("mem_1...", "mem_2..."),
    "en-US",
    "it-IT",
    "Hello World!",
    "Ciao Mondo!"
)
// Add a simple translation unit to an existing memory
var importJob = await translator.Memories.AddTranslation(memory.Id, "en-US", "fr-FR", "Hello", "Bonjour");

// Add a simple translation unit to multiple existing memories
var multiAddResult = await translator.Memories.AddTranslation(memory.Id, "en-US", "fr-FR", "How are you?", "Comment allez-vous?", "greeting_002", "Good morning", "Have a nice day");
// Add a simple translation unit to an existing memory
let importJob = try await lara.memories.addTranslation(
    id: "mem_1...",
    source: "en-US",
    target: "it-IT",
    sentence: "Hello World!",
    translation: "Ciao Mondo!"
)

// Add a simple translation unit to multiple existing memories
let multiImportJob = try await lara.memories.addTranslation(
    ids: ["mem_1...", "mem_2..."],
    source: "en-US",
    target: "it-IT",
    sentence: "Hello World!",
    translation: "Ciao Mondo!"
)
FieldTypeParameter TypeRequiredDefaultDescription
idString | String[]PositionalYes

The ID or list of IDs where to save the translation unit.
Format: mem_xyz123
sourceStringKeywordYes

The source language code of the sentence
targetStringKeywordYes

The target language code of the translation
sentenceStringKeywordYes

The source sentence
translationStringKeywordYes

The translated sentence
tuidStringKeywordNoNullTranslation Unit unique identifier
sentence_beforeStringKeywordNoNullThe sentence before the source sentence to specify the context of the translation unit
sentence_afterStringKeywordNoNullThe sentence after the source sentence to specify the context of the translation unit

Delete Translation (TU) from Memory

Deletes specific translations from a memory. Context information and unique ID can be specified

# Delete a translation unit using a combination of {source, target, sentence, translation}
delete_job = lara.memories.delete_translation(
    'mem_1...',
    source='en-US',
    target='it-IT',
    sentence='Hello World!',
    translation='Ciao Mondo!'
)
// Delete a translation unit using a combination of {source, target, sentence, translation}
const deleteJob = await lara.memories.deleteTranslation(
    'mem_1...',
    'en-US',
    'it-IT',
    'Hello World!',
    'Ciao Mondo!'
);
// Delete a translation unit using a combination of {source, target, sentence, translation}
MemoryImport deleteJob = lara.memories.deleteTranslation(
        "mem_1...",
        "en-US",
        "it-IT",
        "Hello World!",
        "Ciao Mondo!"
);
// Delete a translation unit using a combination of {source, target, sentence, translation}
$deleteJob = $lara->memories->deleteTranslation(
    'mem_1...',
    'en-US',
    'it-IT',
    'Hello World!',
    'Ciao Mondo!'
);
// Delete a translation unit using a combination of {source, target, sentence, translation}
deleteJob, _ := lara.Memories.DeleteTranslation(
	"mem_1...",
	"en-US",
	"it-IT",
	"Hello World!",
	"Ciao Mondo!",
)
// Delete a translation unit using a combination of {source, target, sentence, translation}
val deleteJob: MemoryImport = lara.memories.deleteTranslation(
    "mem_1...",
    "en-US",
    "it-IT",
    "Hello World!",
    "Ciao Mondo!"
)
// Delete a translation unit using a combination of {source, target, sentence, translation}
var deleteJob, _ := lara.Memories.DeleteTranslation(
	"mem_1...",
	"en-US",
	"it-IT",
	"Hello World!",
	"Ciao Mondo!",
)
// Delete a translation unit using a combination of {source, target, sentence, translation}
let deleteJob = try await lara.memories.deleteTranslation(
    id: "mem_1...",
    source: "en-US",
    target: "it-IT",
    sentence: "Hello World!",
    translation: "Ciao Mondo!"
)
FieldTypeRequiredDefaultDescription
idString | String[]Yes

The ID or list of IDs where to delete the translation unit from.
Format: mem_xyz123
sourceStringYes

The source language code of the sentence
targetStringYes

The target language code of the translation
sentenceStringYes

The source sentence
translationStringYes

The translated sentence
tuidStringNoNullTranslation Unit unique identifier
sentence_beforeStringNoNullThe sentence before the source sentence to specify the context of the translation unit
sentence_afterStringNoNullThe sentence after the source sentence to specify the context of the translation unit