Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Translation] correctly handle intl domains with TargetOperation#42361

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:4.4fromacran:4.4
Oct 30, 2021

Conversation

@acran
Copy link
Contributor

@acranacran commentedAug 3, 2021
edited by Nyholm
Loading

QA
Branch?4.4
Bug fix?yes
New feature?no
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

Executingtranslations:update with--clean was producing erratic result: creating duplicate non-/intl files for domains, removing used translations...

TL;DR: judging from context this was most probably just a typo in33e6af5

How to reproduce

Setup Test Project

A fresh minimal project to verify this can be setup with

composer create-project symfony/skeleton translations_testcd translations_test/composer require translation

and adding extractable translations into a file insrc/, e.g.

<?php// in src/translations.phpuseSymfony\Component\Translation\TranslatableMessage;newTranslatableMessage('First Message');newTranslatableMessage('Second Message');

Otherwise any existing project should work as well.

Steps to reproduce

Case 1: duplicate translation files

# remove all existing translations and extract them againrm -rf translations/*php bin/console translation:update --force --clean en# verify translations/messages+intl-icu.en.xlf was created containing the messages# extract messages againphp bin/console translation:update --force --clean en# messages+intl-icu.en.xlf is unchanged but messages.en.xlf with all the same messages was added

Case 2: lost translations

# remove all existing translations and extract them againrm -rf translations/*php bin/console translation:update --force --clean en# verify translations/messages+intl-icu.en.xlf was created containing the messages# remove one or more messages from messages+intl-icu.en.xlf, keeping at least one# extract messages againphp bin/console translation:update --force --clean en# messages+intl-icu.en.xlf will *only* contain the missing/"new" messages and all other messages got removed

The Fix

The previous code was trying to merge with thetarget messages instead of thesource. This was probably just a typo since$keyMetadata is take fromsource just below it and theforeach block below which is basically doing the same inverse just switchestarget andsource.
Also the code is mostly identical toMergeOperation which also usessource at the respective line.

The code in both files was introduced in33e6af5

@carsonbotcarsonbot added this to the4.4 milestoneAug 3, 2021
fabpot added a commit that referenced this pull requestAug 6, 2021
…Commands (acran)This PR was merged into the 5.4 branch.Discussion----------[FrameworkBundle] remove dead conditions in Translation Commands| Q             | A| ------------- | ---| Branch?       | 5.4| Bug fix?      | no| New feature?  | no| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        | -This is just a trivial removal of unused code I stumbled upon while debugging#42361. In the [original code](https://github.com/symfony/symfony/blob/e617a9b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php#L165-L170):~~~php$transPaths = [$path.'/translations'];$codePaths = [$path.'/templates'];if (!is_dir($transPaths[0]) && !isset($transPaths[1])) {throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));}~~~The second part of the condition `isset($transPaths[1])` will **always** evaluate to true, since `$targetPath` is just set 3 lines above but only has a single element.This check was originally to support legacy paths which was removed inb6eb1f4:* in [`TranslationDebugCommand.php`](b6eb1f4#diff-67afa5b8860d0df4e44f1e1fc89f444b7ac77de515b698a6824dd5403a0acdbcL187-L194)* in [`TranslationUpdateCommand.php `](b6eb1f4#diff-a01c7858e84f1868a427634740511da7c8c73e56772baa78bdcd98200d7125c0L180-L187)Rebased from 5.3 to 5.4, see#42362/cc `@fabpot`Commits-------22db5ad [FrameworkBundle] remove dead conditions in Translation Commands
@acran
Copy link
ContributorAuthor

/cc@yceruto

@fabpot
Copy link
Member

@acran Could you add a unit test?

This would cause issues with merging existing intl domains since it wastrying to merge with the target instead of the source.This was originally introduced withc71dfb9The incorrect Test was introduced withb72b7d3
@acran
Copy link
ContributorAuthor

acran commentedSep 2, 2021
edited
Loading

@acran Could you add a unit test?

I can try 🤓
But I'll need probably some feedback on this.

Also digging a bit further in this I found though33e6af5 was the commit that introduced the offendingline it was actually just the result of refactorings and code style fixes and the problem was introduced inc71dfb9. Looking at that commit it definitely smells like a copy&paste mistake.

$this->assertEquals(
newMessageCatalogue('en', [
'messages+intl-icu' => ['a' =>'old_a'],
'messages' => ['a' =>'old_a'],
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Since this is fixing the broken test by sayingthe test was wrong I nowreally need someone with a deep understanding of the code to look into this 🙈

But my reasoning for why this is actually the correct and intended behavior was:
Existing messages shouldalways stay in their current domain. Moving new messages to the intl-icu domain is (at least in recent versions) handled byAbstractOperation::moveMessagesToIntlDomainsIfPossible(), see

$operation->moveMessagesToIntlDomainsIfPossible('new');
and
publicfunctionmoveMessagesToIntlDomainsIfPossible(string$batch =self::ALL_BATCH):void
{
// If MessageFormatter class does not exists, intl domains are not supported.
if (!class_exists(\MessageFormatter::class)) {
return;
}
foreach ($this->getDomains()as$domain) {
$intlDomain =$domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
switch ($batch) {
caseself::OBSOLETE_BATCH:$messages =$this->getObsoleteMessages($domain);break;
caseself::NEW_BATCH:$messages =$this->getNewMessages($domain);break;
caseself::ALL_BATCH:$messages =$this->getMessages($domain);break;
default:thrownew \InvalidArgumentException(sprintf('$batch argument must be one of ["%s", "%s", "%s"].',self::ALL_BATCH,self::NEW_BATCH,self::OBSOLETE_BATCH));
}
if (!$messages || (!$this->source->all($intlDomain) &&$this->source->all($domain))) {
continue;
}
$result =$this->getResult();
$allIntlMessages =$result->all($intlDomain);
$currentMessages =array_diff_key($messages,$result->all($domain));
$result->replace($currentMessages,$domain);
$result->replace($allIntlMessages +$messages,$intlDomain);
}
}

This Test was introduced inb72b7d3 which also should only have affectednew messages. So wasin my interpretation already wrong at that point.

)->getResult()
);

$this->assertEquals(
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This is testing the behavior when merging with new messages and mixed domains. Should this be moved into a separate function/test case? Or is it OK to have it all in the same function?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer a data provider with some explanations for each data, but this is only a recommendation.

@acran
Copy link
ContributorAuthor

Any progress on this? Who could best review this PR??

@fabpot
Copy link
Member

Thank you@acran.

@fabpotfabpot merged commitd146704 intosymfony:4.4Oct 30, 2021
@fabpot
Copy link
Member

@acran Could you do a follow-up PR to take into account@OskarStark's suggestion about documenting the tests?

This was referencedNov 22, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@OskarStarkOskarStarkOskarStark left review comments

@ycerutoycerutoyceruto approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

5 participants

@acran@fabpot@OskarStark@yceruto@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp