fix(xcloc): sync project translations to xliffDoc before export#43
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The export was serializing xliffDoc directly without syncing translations from the project content. When the worker saved content (with translations) but did not save formatData (with xliffDoc), the exported file would be missing all translations. Add syncAllToXliff() method and call it in exportFile() before serializing, mirroring the pattern used by PO client's syncAllToDocument(). Agent-Logs-Url: https://github.com/rxtech-lab/universal-translation/sessions/11861516-0b38-4803-8640-7f3555f7962c Co-authored-by: sirily11 <32106111+sirily11@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes XCLOC exports missing translations by ensuring xliffDoc is synced from the normalized project.resources content immediately before serialization.
Changes:
- Clone
xliffDocinexportFile()and sync project entry translations into the cloned XLIFF document prior to serialization. - Add
syncAllToXliff(doc)helper to apply project translations back into an XLIFF document. - Add a regression test covering
loadFromJson(contentWithTranslations, staleFormatData)and verifying exported XLIFF contains the translations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/translation/xcloc/client.ts | Sync project translations into a cloned XLIFF doc before export to avoid serializing stale formatData.xliffDoc. |
| tests/translation/xcloc/client.test.ts | Adds regression test reproducing stale xliffDoc export and asserting exported XLIFF includes translations. |
| const tu = xliffFile.transUnits.find((t) => t.id === entry.id); | ||
| if (!tu) continue; | ||
|
|
||
| tu.target = entry.targetText; |
There was a problem hiding this comment.
syncAllToXliff() only syncs entry.targetText into tu.target, but does not sync entry.comment into tu.note. If formatData.xliffDoc is stale (the exact scenario this PR fixes), updated entry comments stored in projects.content will still be lost on export. Consider also copying entry.comment to the corresponding trans-unit note during the sync (clearing it when the project comment is empty/undefined).
| tu.target = entry.targetText; | |
| tu.target = entry.targetText; | |
| tu.note = entry.comment ? entry.comment : undefined; |
| tu.target = entry.targetText; | ||
| } |
There was a problem hiding this comment.
syncAllToXliff() assigns tu.target = entry.targetText for every entry. Since the normalized model uses empty string to mean “not translated yet”, this will introduce empty <target></target> elements for all untranslated units when the original XLIFF omitted <target> entirely. To keep export semantics consistent (and avoid bloating the output), consider only setting tu.target when entry.targetText.trim() !== "", and otherwise leaving it undefined/removing it.
|
🎉 This PR is included in version 1.2.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Exported XCLOC files were missing all translations despite the UI showing them as complete.
Root cause: The worker saves translated entries to
projects.contentbut not toprojects.formatData(which holdsxliffDoc). TheexportFile()method serializedxliffDocdirectly—so it exported the stale, untranslated XLIFF.Fix:
syncAllToXliff(doc)toXclocClient, which writesentry.targetTextfromthis.project.resourcesinto the corresponding XLIFF trans-units before serializationexportFile()now always clones and syncs before serializing, matching the pattern already used byPoClient.syncAllToDocument()loadFromJsonwith translated content + stalexliffDoc, verifying the export includes translations