Browse documentation
DocsAPI module

document.regen

Apply translated units to an original file and produce a localized deliverable shaped like its source.

01

Regeneration makes the source contract explicit

document.export.<format>(output) writes the model, with optional or required source arguments for formats such as HTML, Office, and IDML. document.regen.<format>(original, output) gives every regeneration method the same explicit source-first contract. It replaces the modeled translations while retaining unrelated source content, so vendor extensions, package relationships, layout, extra spreadsheet columns, and other unmodeled content can remain with the source instead of being rebuilt from scratch.

02

Produce a localized Office file

Parse the source, attach translations to its units, then regenerate against that same source. DOCX and PPTX return an OfficeExportResult; the other synchronous regeneration methods return None.

regen_docx.py
import lokit
translations: dict[str, str] = {    "Place order": "Passer la commande",}
document = lokit.parse.docx("source.docx")for unit in document.data.values():    translated = translations.get(unit.source)    if translated is not None:        unit.target = translated
result = document.regen.docx(    "source.docx",    "localized.fr.docx",    target_locale="fr-FR",)print(result)
03

Supported regeneration targets

Source formatDocument proxyAsync namespace
CSVdocument.regen.csv()lokit.export.regen.csv_async()
XLSXdocument.regen.xlsx()lokit.export.regen.xlsx_async()
XLIFFdocument.regen.xliff()lokit.export.regen.xliff_async()
TMXdocument.regen.tmx()lokit.export.regen.tmx_async()
PO / POTdocument.regen.po()lokit.export.regen.po_async()
JSON i18ndocument.regen.json_i18n()lokit.export.regen.json_i18n_async()
HTMLdocument.regen.html()lokit.export.regen.html_async()
IDMLdocument.regen.idml()lokit.export.regen.idml_async()
DOCXdocument.regen.docx()lokit.export.regen.docx_async()
PPTXdocument.regen.pptx()lokit.export.regen.pptx_async()
04

Streaming regeneration stays one pass

Most regeneration functions accept BaseStructure or StreamingStructure. A streaming document is consumed in unit order by the regeneration provider, so the application does not need to materialize the complete translation set first. XML regeneration uses event-driven rewriting; archive-based formats copy the source package while replacing the parts Lokit owns. IDML regeneration currently requires a materialized BaseStructure.

05

Regenerate asynchronously

Async functions are exposed from lokit.export.regen with an _async suffix. They run blocking file or Office work away from the calling event loop while preserving the same original-file and output-file contract.

regen_async.py
import lokit
document = lokit.parse.xliff("source.xliff")
await lokit.export.regen.xliff_async(    document,    "source.xliff",    "localized.fr.xliff",    target_locale="fr-FR",)
06

Use distinct input and output paths

Treat the original as an immutable template and write the localized result to a different path. Select target_locale explicitly for multilingual documents. For CSV and XLSX, retain the detected header and column options unless the source uses a custom layout; regeneration can preserve extra columns and map multiple target columns.