add_translation
Adds a translation to a translation memory in your Lara Translate account by specifying source and target languages, sentences, and translation units.
Instructions
Adds a translation to a translation memory in your Lara Translate account.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID or list of IDs where to save the translation unit. Format: mem_xyz123 | |
| source | Yes | The source language code of the sentence, it MUST be a language supported by the system, use the list_languages tool to get a list of all the supported languages | |
| target | Yes | The target language code of the translation, it MUST be a language supported by the system, use the list_languages tool to get a list of all the supported languages | |
| sentence | Yes | The source sentence | |
| translation | Yes | The translated sentence | |
| tuid | No | Translation Unit unique identifier | |
| sentence_before | No | The sentence before the source sentence to specify the context of the translation unit | |
| sentence_after | No | The sentence after the source sentence to specify the context of the translation unit |
Implementation Reference
- src/mcp/tools/add_translation.ts:37-77 (handler)The main handler function 'addTranslation' that implements the core logic of the 'add_translation' tool. It parses arguments using the schema, handles conditional logic for context sentences, and calls the underlying Lara API.export async function addTranslation(args: unknown, lara: Translator) { const validatedArgs = addTranslationSchema.parse(args); const { id, source, target, sentence, translation, tuid, sentence_before, sentence_after, } = validatedArgs; if (!tuid) { return await lara.memories.addTranslation( id, source, target, sentence, translation ); } if ( (sentence_before && !sentence_after) || (!sentence_before && sentence_after) ) { throw new Error("Please provide both sentence_before and sentence_after"); } return await lara.memories.addTranslation( id, source, target, sentence, translation, tuid, sentence_before, sentence_after ); }
- Zod schema 'addTranslationSchema' defining the input validation for the 'add_translation' tool, including parameters like id, source, target, sentence, translation, and optional context.export const addTranslationSchema = z.object({ id: z .array(z.string()) .describe( "The ID or list of IDs where to save the translation unit. Format: mem_xyz123" ), source: z .string() .describe( "The source language code of the sentence, it MUST be a language supported by the system, use the list_languages tool to get a list of all the supported languages" ), target: z .string() .describe( "The target language code of the translation, it MUST be a language supported by the system, use the list_languages tool to get a list of all the supported languages" ), sentence: z.string().describe("The source sentence"), translation: z.string().describe("The translated sentence"), tuid: z.string().describe("Translation Unit unique identifier").optional(), sentence_before: z .string() .describe( "The sentence before the source sentence to specify the context of the translation unit" ) .optional(), sentence_after: z .string() .describe( "The sentence after the source sentence to specify the context of the translation unit" ) .optional(), });
- src/mcp/tools.ts:36-45 (registration)Registration of the 'add_translation' handler in the central handlers map used by CallTool to dispatch tool calls.const handlers: Record<string, Handler> = { translate: translateHandler, create_memory: createMemory, delete_memory: deleteMemory, update_memory: updateMemory, add_translation: addTranslation, delete_translation: deleteTranslation, import_tmx: importTmx, check_import_status: checkImportStatus, };
- src/mcp/tools.ts:114-119 (registration)Registration of the 'add_translation' tool in the ListTools response, including its name, description, and input schema.{ name: "add_translation", description: "Adds a translation to a translation memory in your Lara Translate account.", inputSchema: z.toJSONSchema(addTranslationSchema), },
- src/mcp/tools.ts:8-11 (registration)Import statement bringing in the addTranslation handler and addTranslationSchema from the add_translation module.import { addTranslation, addTranslationSchema, } from "./tools/add_translation.js";