-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
[FrameworkBundle] Allow to specify a domain when updating translations #19325
Conversation
@@ -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'))); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ?
@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)) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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)
@nicolas-grekas thanks for your explanation on the Travis build and your review. |
Looks like your target can be achieved with changing the translation component: |
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. |
@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. |
@nicolas-grekas I now understood your first comment. Yes I'm missing a test case. 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. The only solution that I can see without updating the translation component would be to find a way to filter |
@antograssiot see updated patch at master...nicolas-grekas:console-translation-domain-choice |
@nicolas-grekas It works fine in my case but I'm concerned about |
I didn't spot the method was private, fixed. No need to close this PR, just make my patch yours by doing e.g.:
|
PR updated. Thank you very much @nicolas-grekas for your help and patience |
👍 |
Thank you @antograssiot. |
…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
… 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
The MR add the
--domain
option to thetranslation:update
console commandWhen working with large number of domains, this helps to reduce the noise in the diff when updating only a translation file.