Skip to content

[FrameworkBundle] Allow to specify a domain when updating translations #19325

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
Jul 18, 2016
Merged

[FrameworkBundle] Allow to specify a domain when updating translations #19325

merged 1 commit into from
Jul 18, 2016

Conversation

antograssiot
Copy link
Contributor

@antograssiot antograssiot commented Jul 9, 2016

Q A
Branch? "master"
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes/
Fixed tickets
License MIT
Doc PR no

The MR add the --domain option to the translation:update console command
When working with large number of domains, this helps to reduce the noise in the diff when updating only a translation file.

@@ -203,8 +211,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$bundleTransPath) {
$bundleTransPath = end($transPaths).'translations';
}

$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath, 'default_locale' => $this->getContainer()->getParameter('kernel.default_locale')));
$writer->writeTranslations($operation->getResult($input->getOption('domain')), $input->getOption('output-format'), array('path' => $bundleTransPath, 'default_locale' => $this->getContainer()->getParameter('kernel.default_locale')));
Copy link
Member

Choose a reason for hiding this comment

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

but getResult takes no arguments, or did I miss something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas I added an optional one in src/Symfony/Component/Translation/Catalogue/AbstractOperation.php

@antograssiot
Copy link
Contributor Author

ping @nicolas-grekas I've updated as requested.

@@ -150,9 +150,13 @@ public function getObsoleteMessages($domain)
/**
* {@inheritdoc}
*/
public function getResult()
public function getResult($domain = null)
Copy link
Member

@nicolas-grekas nicolas-grekas Jul 17, 2016

Choose a reason for hiding this comment

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

I'm not comfortable with this change. The $operation should already have filtered domains.
I see two alternatives: add setDomains() on AbstractOperation, or add a $domains argument to MessageCatalogue to make it filter messages it can contain. A third alt. would be to filter at the loader/extractor level, but they look too specific for this. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Or fourth way, maybe the less intrusive one: filter the result itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with adding setDomains(). but I can still try to update if you want.
Also do you want me to squash the 2 commits ?

@antograssiot
Copy link
Contributor Author

@nicolas-grekas the tests are passing locally but fails with low deps on travis due to composer issue. This doesn't seems related to my change, am I right ?

// Exit if no messages found.
if (!count($operation->getDomains())) {
if (!count($domains)) {
Copy link
Member

Choose a reason for hiding this comment

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

Change not needed anymore, same below

Copy link
Contributor Author

@antograssiot antograssiot Jul 17, 2016

Choose a reason for hiding this comment

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

that was still to avoid some function call but I can remove it

@nicolas-grekas
Copy link
Member

FrameworkBundle now needs Translation 3.2, that's why lowest tests are failing

$domain = $input->getOption('domain');

if (null !== $domain) {
$domains = array_intersect($domains, array($domain));
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this line: when the option is set, let's call setDomains with it

Copy link
Member

Choose a reason for hiding this comment

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

I may be wrong though here :)

Copy link
Contributor Author

@antograssiot antograssiot Jul 17, 2016

Choose a reason for hiding this comment

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

I'll leave the array_intersect() because if you use for example --domain nonexisting
Then you'll get an empty array when calling getDomains() and the command will exit (L155-158)

@antograssiot
Copy link
Contributor Author

@nicolas-grekas thanks for your explanation on the Travis build and your review.
It should now be limited to the minimum changes.

@nicolas-grekas nicolas-grekas changed the title [Console] [FrameworkBundle] Allow to specify a domain when updating translation [FrameworkBundle] Allow to specify a domain when updating translations Jul 17, 2016
@nicolas-grekas
Copy link
Member

Looks like your target can be achieved with changing the translation component:
master...nicolas-grekas:console-translation-domain-choice
Or do you miss a test case?

@antograssiot
Copy link
Contributor Author

Nicolas I'm sorry I don't get your comment. You tm branch is not up to date with mine but I tested it again in an app and it seems to work as expected.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 17, 2016

@antograssiot if you're fine with my patch, then make it yours. If we don't need to change anything in the translation component, it's better.

@antograssiot
Copy link
Contributor Author

antograssiot commented Jul 17, 2016

@nicolas-grekas I now understood your first comment. Yes I'm missing a test case.
Your patch will only work when using the --dump-messages flag but when using --force all files will still get generated, that's how I came to modify the AbstractOperation.

A test proving that only one file is generated is missing. I tried to wrote one but I failed and I couldn't find any existing test that could guide me. $this->translationDir.'/Resources/translations seems to always stay empty.

The only solution that I can see without updating the translation component would be to find a way to filter $operation->getResult() fro TranslationUpdateCommand.phpbut I don't know how.

@nicolas-grekas
Copy link
Member

@antograssiot
Copy link
Contributor Author

@nicolas-grekas It works fine in my case but I'm concerned about MessageCatalogue::addMetadata() being a private function.
Thanks for your work on patching this anyway, should I close my PR ?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jul 18, 2016

I didn't spot the method was private, fixed. No need to close this PR, just make my patch yours by doing e.g.:

git checkout console-translation-domain-choice
git fetch https://github.com/nicolas-grekas/symfony.git console-translation-domain-choice
git reset --hard FETCH_HEAD
git push -f origin console-translation-domain-choice

@antograssiot
Copy link
Contributor Author

PR updated. Thank you very much @nicolas-grekas for your help and patience

@nicolas-grekas
Copy link
Member

👍

@fabpot
Copy link
Member

fabpot commented Jul 18, 2016

Thank you @antograssiot.

@fabpot fabpot merged commit a8f3a93 into symfony:master Jul 18, 2016
fabpot added a commit that referenced this pull request Jul 18, 2016
…ing translations (antograssiot)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[FrameworkBundle] Allow to specify a domain when updating translations

| Q             | A
| ------------- | ---
| Branch?       | "master"
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes/
| Fixed tickets |
| License       | MIT
| Doc PR        | no

The MR add the `--domain` option to the `translation:update` console command
When working with large number of domains, this helps to reduce the noise in the diff when updating only a translation file.

Commits
-------

a8f3a93 [FrameworkBundle] Allow to specify a domain when updating translations
nicolas-grekas added a commit that referenced this pull request Sep 13, 2016
… a merge (jakzal)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[FrameworkBundle] Fix TranslationUpdateCommand tests after a merge

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19921
| License       | MIT
| Doc PR        | -

#19325 relied on a wrong count of messages, which was fixed by #19878.
Additionally, the `getContainer()` method on the master branch expect messages to be indexed by domain.

Commits
-------

d093c40 [FrameworkBundle] Fix TranslationUpdateCommand tests after a merge
@fabpot fabpot mentioned this pull request Oct 27, 2016
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