Skip to content

Conversation

@mauricedefelicec24
Copy link

@mauricedefelicec24 mauricedefelicec24 commented Oct 9, 2025

Q A
Branch? 7.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #33041
License MIT

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:

  1. XliffFileDumper - Updated to use metadata['source'] when available for both XLIFF 1.2 and 2.0 formats
  2. XliffFileLoader - Updated to store the source text in metadata when loading XLIFF 2.0 files
  3. Added comprehensive unit tests to verify the behavior

Before / After Comparison

Before:

<trans-unit id="0umDnnC" resname="navbar.home">
  <source>navbar.home</source>
  <target>Accueil</target>
</trans-unit>

After (with metadata):

<trans-unit id="0umDnnC" resname="navbar.home">
  <source>Home</source>
  <target>Accueil</target>
</trans-unit>

How it works

When a MessageCatalogue has metadata['source'] set for a translation key:

$catalogue = new MessageCatalogue('fr');
$catalogue->set('navbar.home', 'Accueil', 'messages');
$catalogue->setMetadata('navbar.home', ['source' => 'Home'], 'messages');

$dumper = new XliffFileDumper();
$xliff = $dumper->formatCatalogue($catalogue, 'messages', ['default_locale' => 'en']);
// Generates: <source>Home</source> instead of <source>navbar.home</source>

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 metadata
  • testFormatCatalogueXliff2WithSourceMetadata() - Verifies XLIFF 2.0 uses source metadata
  • testFormatCatalogueWithoutSourceMetadataFallsBackToKey() - Ensures backward compatibility
  • testLoadVersion2StoresSourceInMetadata() - Verifies loader stores source in metadata

All tests pass successfully.


Benefits

This fix enables:

  • XLIFF compliance - Files now conform to the XLIFF specification
  • Better translation workflows - Translation software can display both the key (resname) and original text (source)
  • Automated translation support - Services like DeepL can translate the meaningful source text instead of keys
  • Clearer context - Translators see "Home" instead of "navbar.home", making their work easier

Related Issues

@carsonbot carsonbot added this to the 7.4 milestone Oct 9, 2025
@carsonbot carsonbot changed the title Store and utilize source metadata in XLIFF files. Store and utilize source metadata in XLIFF files. Oct 9, 2025
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.4" but it seems your PR description refers to branch "6.4".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title Store and utilize source metadata in XLIFF files. [Translation] Store and utilize source metadata in XLIFF files. Nov 7, 2025
@nicolas-grekas nicolas-grekas modified the milestones: 7.4, 8.1 Nov 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XLIFF export should contain default locale default texts in source tags

3 participants