8000 [Translation] Xliff name attribute as the key. · Issue #37055 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[Translation] Xliff name attribute as the key. #37055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
idybil opened this issue Jun 2, 2020 · 6 comments
Closed

[Translation] Xliff name attribute as the key. #37055

idybil opened this issue Jun 2, 2020 · 6 comments

Comments

@idybil
Copy link
idybil commented Jun 2, 2020

Symfony version(s) affected: 5.1.0

Description
In the translation xliff dumper (translation/Dumper/XliffFileDumper.php), When a string length is greater than 80, the dumper (translation/Dumper/XliffFileDumper.php) set the name attribute of the unit using md5.

But since the xliff loader is now using the name attribute as the key (#35373), the translation is missing when generating the template.

How to reproduce

  • In a Twig template or using the translator->trans(), add a string to be translated with a length greater than 80 characters.

  • Dump the translation (I'm using the php-translation/symfony-bundle)

  • See the result in a browser: the translated string is always displayed in the default locale, plus, in the profiler, it is displayed as "missing" translation.

Possible Solution

I know I can use translation keys, but prefer to stick with content strings.

@idybil idybil added the Bug label Jun 2, 2020
@idybil idybil changed the title [Translation] [Translation] Xliff name attribute as the key. Jun 2, 2020
@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@idybil
Copy link
Author
idybil commented Feb 19, 2021

I think this should be fixed.

@carsonbot carsonbot removed the Stalled label Feb 19, 2021
@oto-djo
Copy link
oto-djo commented Feb 19, 2021

I have the same problem.

@derrabus
Copy link
Member

@idybil @damien-jourdan Does #40283 fix your problem?

@oto-djo
Copy link
oto-djo commented Feb 24, 2021

@derrabus Yes !

nicolas-grekas added a commit that referenced this issue Feb 24, 2021
…rieMinasyan)

This PR was submitted for the 5.2 branch but it was merged into the 4.4 branch instead.

Discussion
----------

[Translation] Make `name` attribute optional in xliff2

Do not set a fake `name` attribute on `unit` element from xliff2 to allow using `source` attribute and avoid missing translation error

| Q             | A
| ------------- | ---
| Branch?       | 5.2
| Bug fix?      | yes/no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37055
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

When `xlf` translations are loaded, if a name exists on `unit` element, the segment's source is ignored:
```foreach ($xml->xpath('//xliff:unit') as $unit) {
            foreach ($unit->segment as $segment) {
                $attributes = $unit->attributes();
                $source = $attributes['name'] ?? $segment->source;
```

At the same time, when dumping translations, the segment's source is copied into the unit's name attribute, unless it's longer than 80 characters. In that case, `substr(md5($source), -7)` is set into the name attribute.
This results in a missing translation error, because the source is ignored and the name is a random string.

Suggested solution: only set the name attribute if the string is less than 80 characters.

Commits
-------

9705855 [Translation] Make `name` attribute optional in xliff2
@idybil
Copy link
Author
idybil commented Feb 24, 2021

Thanks guys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
0