Browse documentation
document.regen
Apply translated units to an original file and produce a localized deliverable shaped like its source.
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.
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.
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)Supported regeneration targets
| Source format | Document proxy | Async namespace |
|---|---|---|
| CSV | document.regen.csv() | lokit.export.regen.csv_async() |
| XLSX | document.regen.xlsx() | lokit.export.regen.xlsx_async() |
| XLIFF | document.regen.xliff() | lokit.export.regen.xliff_async() |
| TMX | document.regen.tmx() | lokit.export.regen.tmx_async() |
| PO / POT | document.regen.po() | lokit.export.regen.po_async() |
| JSON i18n | document.regen.json_i18n() | lokit.export.regen.json_i18n_async() |
| HTML | document.regen.html() | lokit.export.regen.html_async() |
| IDML | document.regen.idml() | lokit.export.regen.idml_async() |
| DOCX | document.regen.docx() | lokit.export.regen.docx_async() |
| PPTX | document.regen.pptx() | lokit.export.regen.pptx_async() |
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.
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.
import lokit
document = lokit.parse.xliff("source.xliff")
await lokit.export.regen.xliff_async( document, "source.xliff", "localized.fr.xliff", target_locale="fr-FR",)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.