Browse documentation
TMX
Choose a target, retain inline tags, materialize, stream, or parallelize large translation memories.
Parse a translation memory
source_language and target_language select languages from a multilingual TMX. TmxParseMode.FULL is the default. Lokit retains inline maps and ordered parts in the default plain-text model; include_tags=True additionally renders markup into returned strings. See Tags & inline content before editing formatted segments.
import lokitfrom lokit.parse import TmxParseMode
document = lokit.parse.tmx( "memory.tmx", source_language="en", target_language="fr", mode=TmxParseMode.FULL, include_tags=True,)Stream or parallelize
stream.tmx() returns a StreamingStructure; iterate its .items. parse.tmx_parallel() and stream.tmx_parallel() use a process pool and are most useful for sufficiently large inputs. Async TMX is an async unit iterator; stream.async_.tmx_batches() yields bounded batches.
stream = lokit.stream.tmx("memory.tmx", target_language="fr")for unit_id, unit in stream.items: consume(unit_id, unit)
async for batch in lokit.stream.async_.tmx_batches( "memory.tmx", target_language="fr", batch_size=1_000,): await consume_batch(batch)Split a multilingual TMX
Call split_targets() without locales to discover every target, or pass a tuple to select a subset. Materialized splits are independent documents; streaming splits use a one-shot context manager. The splitting guide documents metadata overlays, missing targets, stable IDs, and temporary-spool lifetime.
document = lokit.parse.tmx("multilingual.tmx", progress=False)for locale, localized in document.split_targets(include_missing=False).items(): localized.export.tmx(f"memory.{locale}.tmx")Write new or regenerate original
lokit.write.tmx() creates a canonical TMX from the common model. Use document.regen.tmx(original, output) when preserving the original XML envelope and unmodeled content matters.
lokit.write.tmx(document, "new-memory.tmx")document.regen.tmx("original.tmx", "updated.tmx", target_locale="fr-FR")