import_tmx
Upload TMX file content to update a translation memory in Lara Translate, enabling reuse of existing translations for consistent localization.
Instructions
Imports a TMX file into a translation memory in your Lara Translate account.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the memory to update. Format: mem_xyz123. | |
| tmx_content | Yes | The content of the tmx file to upload. |
Implementation Reference
- src/mcp/tools/import_tmx.ts:20-48 (handler)The async importTmx function that parses arguments with the schema, checks TMX size limit, creates temp directory and file, imports via lara.memories.importTmx, and cleans up the temp file.export async function importTmx(args: any, lara: Translator) { const validatedArgs = importTmxSchema.parse(args); const { id, tmx_content } = validatedArgs; // File size limit: 5MB const MAX_TMX_SIZE = 5 * 1024 * 1024; // 5MB if (Buffer.byteLength(tmx_content, 'utf8') > MAX_TMX_SIZE) { throw new Error("TMX file too large. Maximum allowed size is 5MB."); } const tempDir = path.join(os.tmpdir(), 'lara-tmx-imports'); if (!fs.existsSync(tempDir)) { fs.mkdirSync(tempDir, { recursive: true }); } const tempFilePath = path.join(tempDir, `tmx-${Date.now()}-${Math.random().toString(36).slice(2)}.tmx`); try { fs.writeFileSync(tempFilePath, tmx_content); return await lara.memories.importTmx(id, tempFilePath); } catch (err) { throw err; } finally { if (fs.existsSync(tempFilePath)) { fs.unlinkSync(tempFilePath); } } }
- src/mcp/tools/import_tmx.ts:7-18 (schema)Zod input validation schema for the import_tmx tool, defining 'id' (string, memory ID) and 'tmx_content' (string, TMX file content).export const importTmxSchema = z.object({ id: z .string() .describe( "The ID of the memory to update. Format: mem_xyz123." ), tmx_content: z .string() .describe( "The content of the tmx file to upload." ), });
- src/mcp/tools.ts:36-45 (registration)Registration of tool handlers in the 'handlers' map, mapping 'import_tmx' to the importTmx function for dispatch in CallTool.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:126-131 (registration)Registration of the 'import_tmx' tool metadata (name, description, inputSchema) in the ListTools response.{ name: "import_tmx", description: "Imports a TMX file into a translation memory in your Lara Translate account.", inputSchema: z.toJSONSchema(importTmxSchema), },