add_translation
Add a translation unit to your translation memory with source and target language, sentence, translation, and optional context.
Instructions
Adds a translation to a translation memory in your Lara Translate account.
Input 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:38-78 (handler)The main handler function that executes the add_translation tool logic. It validates inputs via the schema, then calls lara.memories.addTranslation() with or without optional tuid/context parameters.
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 InvalidInputError("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 defining the input validation for add_translation, including required fields (id, source, target, sentence, translation) and optional fields (tuid, sentence_before, sentence_after).
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:8-11 (registration)Import statement bringing addTranslation handler and schema into the main tools registry.
import { addTranslation, addTranslationSchema, } from "./tools/add_translation.js"; - src/mcp/tools.ts:54-54 (registration)Handler mapping that registers 'add_translation' tool name to the addTranslation function.
add_translation: addTranslation, - src/mcp/tools.ts:267-278 (registration)Tool definition with name, description, inputSchema, and annotations (title, readOnlyHint, destructiveHint) for the 'add_translation' tool.
{ name: "add_translation", description: "Adds a translation to a translation memory in your Lara Translate account.", inputSchema: z.toJSONSchema(addTranslationSchema), annotations: { title: "Add translation unit to memory", readOnlyHint: false, destructiveHint: false, openWorldHint: false, }, },