Skip to content

[Translation] Fix translator overlapse #46190

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

Merged
merged 1 commit into from
Aug 2, 2022

Conversation

xavren
Copy link
Contributor

@xavren xavren commented Apr 27, 2022

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #46189
License MIT
Doc PR symfony/symfony-docs#...

@carsonbot carsonbot added this to the 4.4 milestone Apr 27, 2022
@carsonbot carsonbot changed the title [Translator] Fix translator overlapse [Translation] Fix translator overlapse Apr 27, 2022
@xavren xavren force-pushed the fix-translator-overlapse branch from 0fcdc41 to 5925013 Compare April 27, 2022 15:29
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry but this does not make sense to me as MessageCatalog::get() starts with:

        if (isset($this->messages[$domain.self::INTL_DOMAIN_SUFFIX][$id])) {
            return $this->messages[$domain.self::INTL_DOMAIN_SUFFIX][$id];
        }

To confirm, I checked out the PR and reverted the patch: tests still pass.
Can you figure out a tests that fails without the patch?

@nicolas-grekas
Copy link
Member

@xavren still up to finish this one? Can you figure out a failing test case?

@xavren
Copy link
Contributor Author

xavren commented Jun 20, 2022

@nicolas-grekas sorry for the delay, we had some new priorities and forgot to follow this issue.

You are right, this is not the issue, but the bug exists as demonstrated by this https://github.com/xavren/symfony-translator-bug/blob/master/src/Command/TestCommand.php

Code

$output->writeln($this->translator->trans('test', ['name' => 'World']));
$output->writeln($this->translator->trans('test', ['name' => 'World'], 'messages+intl-icu'));
$output->writeln($this->translator->trans('test', ['name' => 'World'], 'messages'));

Result is

php bin/console app:test
Hello %name%
Hello %World%
Hello %name%

It seems that MessageCatalogue loading messages has an issue but cannot spot it and did not find any tests :/

For the debug, here is the cache file

var/cache/dev/translations/catalogue.en.bBuRKVV.php

<?php

use Symfony\Component\Translation\MessageCatalogue;

$catalogue = new MessageCatalogue('en', array (
  'messages+intl-icu' => 
  array (
    'test' => 'Hello %name%',
  ),
));


return $catalogue;

@stof
Copy link
Member

stof commented Jun 20, 2022

Well, using %name% in a catalogue that has the intl suffix is not replaced at all and this is expected, as this is not a placeholder at all in the ICU message format.

@xavren
Copy link
Contributor Author

xavren commented Jun 20, 2022

Completly ok with that, but you can see the content of my translations files
image

Result is completly mixed up

@stof
Copy link
Member

stof commented Jun 20, 2022

@xavren The legacy format replaces whatever you pass as key. so to replace %name%, you need to pass %name% as key, not name (as part if the Intl ICU message format migration, % are trimmed from the placeholder name, but they are not added automatically)

@xavren
Copy link
Contributor Author

xavren commented Jun 20, 2022

@stof, the idea was to show mixup catalogue data, we have legacy data in intl-icu domain, that override intl-icu data, formatted by intlFormatter.
If you tell me this is what's expected, i'll close this issue

@xavren xavren force-pushed the fix-translator-overlapse branch 2 times, most recently from 361394e to 44fd6d0 Compare June 21, 2022 09:24
@stof
Copy link
Member

stof commented Jun 21, 2022

you should not have legacy data in your intl-icu catalogue. That should go in the non-suffixed catalogue for that domain. Putting legacy data in the catalogue that is meant to contain ICU format will indeed not work, and that's totally expected.

@xavren
Copy link
Contributor Author

xavren commented Jun 21, 2022

Hi @stof and @nicolas-grekas, i modified my PR adding tests that demonstrate the issue (hopefully)

public function testIntlDomainOverlapseWithIntlResourceBefore() does not pass, because MessageCatalogue is mixing up legacy / intl domains

@nicolas-grekas nicolas-grekas force-pushed the fix-translator-overlapse branch from 44fd6d0 to 99ca5f9 Compare August 2, 2022 12:51
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue was likely introduced in #35430
I fixed it, all green. Thanks for the test case.

@nicolas-grekas
Copy link
Member

Thank you @xavren.

@nicolas-grekas nicolas-grekas merged commit 23c6b9d into symfony:4.4 Aug 2, 2022
This was referenced Aug 26, 2022
@fabpot fabpot mentioned this pull request Aug 26, 2022
@fabpot fabpot mentioned this pull request Sep 30, 2022
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.

4 participants