[Translation] Store and utilize source metadata in XLIFF files. #62023
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the XLIFF export format to comply with the XLIFF specification. Previously, the
<source>tags contained translation keys instead of the default locale text, making the exported files non-compliant and difficult to use with translation management software.What it does and why it's needed
The XLIFF specification requires that
<source>tags contain the original text to be translated (from the default locale), not the translation key. This fix modifies:XliffFileDumper- Updated to usemetadata['source']when available for both XLIFF 1.2 and 2.0 formatsXliffFileLoader- Updated to store the source text in metadata when loading XLIFF 2.0 filesBefore / After Comparison
Before:
After (with metadata):
How it works
When a
MessageCataloguehasmetadata['source']set for a translation key:Backward Compatibility
✅ Fully backward compatible - If
metadata['source']is not set, the dumper falls back to using the translation key as before, ensuring existing workflows continue to work.Tests Added
testFormatCatalogueWithSourceMetadata()- Verifies XLIFF 1.2 uses source metadatatestFormatCatalogueXliff2WithSourceMetadata()- Verifies XLIFF 2.0 uses source metadatatestFormatCatalogueWithoutSourceMetadataFallsBackToKey()- Ensures backward compatibilitytestLoadVersion2StoresSourceInMetadata()- Verifies loader stores source in metadataAll tests pass successfully.
Benefits
This fix enables:
resname) and original text (source)Related Issues