8000 Translation keys not in Sync with Loco | Duplicated from Loco · Issue #189 · php-translation/symfony-bundle · GitHub
[go: up one dir, main page]

Skip to content
Translation keys not in Sync with Loco | Duplicated from Loco #189
@dkozickis

Description

@dkozickis

Hi!

I have an issue with translation keys going in and out of Loco and getting duplicated a lot.
I've traced this down (I think), and wanted your opinion on what's the correct way forward fixing it.

First of all - here's a reproducer - https://github.com/dkozickis/translation-issue-reproducer
Just change the Loco AP key in config/packages/php_translation.yml

templates/base.html.twig contains the example string

Run: php bin/console translation:extract

Below is generated, as you can see translation id is X8pvpvu:

<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en" trgLang="en">
  <file id="messages.en">
    <unit id="X8pvpvu">
      <notes>
        <note category="file-source" priority="1">templates/base.html.twig:10</note>
        <note category="state" priority="1">new</note>
      </notes>
      <segment>
        <source>test_translate</source>
        <target></target>
      </segment>
    </unit>
  </file>
</xliff>

First php bin/console translate:sync app gives expected results, string goes into Loco.
Second php bin/console translate:sync app gives unexpected results:

<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en" trgLang="en">
  <file id="messages.en">
    <unit id="X8pvpvu">
      <notes>
        <note category="file-source" priority="1">templates/base.html.twig:10</note>
      </notes>
      <segment>
        <source>test_translate</source>
        <target></target>
      </segment>
    </unit>
    <unit id="CYJwdyK">
      <segment>
        <source>X8pvpvu</source>
        <target>test_translate</target>
      </segment>
    </unit>
  </file>
</xliff>

As you see, we now have a duplicate with source same as original string key.

There are couple things that cause this.

  1. By default sync command runs following:

$this->mergeDown();
$this->mergeUp();

Meaning that during sync, with Loco adapter, first all data from Loco will be downloaded, then all data will be uploaded to Loco.

Given that we've already done first sync, second sync will produce following XLIFF result from Loco:

<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
    <file source-language="en" target-language="en" tool-id="loco" datatype="plaintext" original="file.ext">
        <header>
            <tool tool-id="loco" tool-name="Loco for Symfony" tool-version="1.0.18 20180126-1" tool-company="Loco" />
        </header>
        <body>
            <trans-unit id="loco:5a7185a4820ee945368b4567">
                <source>X8pvpvu</source>
                <target>test_translate</target>
            </trans-unit>
        </body>
    </file>
</xliff>

For whatever the magic reason, Loco have put <unit id=> from initial exract into <source>
At this point, Xliff Dumper (part of symfony-storage lib) grabs the <source> from Loco dump, and generates a new <unit id=>, thus we arrive to unexpected results mentioned above.

After that data is uploaded to Loco, and the new key is now reimported into Loco, essentially duplicating everything, after every translate:sync

My current workaround for this is to have custom Xliff Dumper overriding standard symfony/translation Xliff Dumper (works during translate:extract) and custom fork of symfony-storage overring Xliff Dumper there (duplication in symfony-storage). My Xliff Dumpers just take <source> as <unit id>, thus, when I load into Loco, I load with the same key as source, and when I download from Loco, I get <source> same as existing <key> in existing translation files, this helps me avoid duplication.

Hope my description was clear...

What I want to know:

  • Is my Loco setup incorrect?
  • Is my bundle setup incorrect?
  • Is this intended behaviour (and caused by my incorrect setup)?
  • If this is a bug - how would you like to fix it @Nyholm ?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0