Browse documentation
DocsFormat guide

XLIFF

Parse XLIFF 1.2 and 2.x into the shared model, including multi-file containers and inline content.

01

Parse and stream

The XLIFF parser handles container metadata and maps translatable units into BaseStructure. Native inline maps and parts are retained with plain text by default; use include_tags=True only when the returned strings themselves must contain rendered inline syntax. The tag integrity guide covers cross-version and cross-format conversion.

xliff.py
import lokit
document = lokit.parse.xliff("messages.xliff", include_tags=True)
stream = lokit.stream.xliff("messages.xliff")for unit_id, unit in stream.items:    print(unit_id, unit.source)
02

Async iteration

The async surface returns units directly and does not first construct a BaseStructure.

xliff_async.py
async for unit_id, unit in lokit.parse.async_.xliff(    "messages.xliff",    include_tags=True,):    await index_unit(unit_id, unit)
03

Split targets and retain XLIFF resources

split_targets() creates one document per locale. Export each result with group_by_resource=True to preserve original resource grouping as XLIFF <file> elements. See TMX, XLIFF & file splitting for collision-safe IDs, missing-unit behavior, and streaming splits.

split_xliff.py
document = lokit.parse.xliff("multilingual.xliff")for locale, localized in document.split_targets().items():    localized.export.xliff(        f"messages.{locale}.xliff",        group_by_resource=True,    )
04

Create versus regenerate

The canonical writer can group units by their resource metadata. Regeneration updates targets in the original document and is the safer choice when a vendor-specific envelope must survive.

write_xliff.py
lokit.write.xliff(document, "new.xliff", group_by_resource=True)document.regen.xliff("original.xliff", "updated.xliff", target_locale="fr-FR")