8000 feature #38393 [FrameworkBundle] Add option --as-tree to translation:… · symfony/symfony@81833b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 81833b6

Browse files
committed
feature #38393 [FrameworkBundle] Add option --as-tree to translation:update command (jschaedl)
This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [FrameworkBundle] Add option --as-tree to translation:update command | Q | A | ------------- | --- | Branch? | master<!-- see below --> | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? |no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #38344 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | tbd. <!-- required for new featur 8000 es --> Before: ``` $ bin/console translation:update --domain messages --output-format=yml --force en # messages.yaml app.backend.title: __app.backend.title app.backend.content: __app.backend.content ``` After: ``` $ bin/console translation:update --domain messages --output-format=yml --force --as-tree=3 en # messages.yaml app: backend: title: __app.backend.title content: __app.backend.content ``` Commits ------- 62cb77a [FrameworkBundle] Add option --as-tree to translation:update command
2 parents c4141f5 + 62cb77a commit 81833b6

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CHANGELOG
1313
* added `framework.http_client.retry_failing` configuration tree
1414
* added `assertCheckboxChecked()` and `assertCheckboxNotChecked()` in `WebTestCase`
1515
* added `assertFormValue()` and `assertNoFormValue()` in `WebTestCase`
16+
* Added "--as-tree=3" option to `translation:update` command to dump messages as a tree-like structure. The given value defines the level where to switch to inline YAML
1617

1718
5.1.0
1819
-----

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ protected function configure()
8484
new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'Specify the domain to update'),
8585
new InputOption('xliff-version', null, InputOption::VALUE_OPTIONAL, 'Override the default xliff version', '1.2'),
8686
new InputOption('sort', null, InputOption::VALUE_OPTIONAL, 'Return list of messages sorted alphabetically', 'asc'),
87+
new InputOption('as-tree', null, InputOption::VALUE_OPTIONAL, 'Dump the messages as a tree-like structure: The given value defines the level where to switch to inline YAML'),
8788
])
8889
->setDescription('Updates the translation file')
8990
->setHelp(<<<'EOF'
@@ -108,6 +109,12 @@ protected function configure()
108109
109110
<info>php %command.full_name% --dump-messages --sort=asc en AcmeBundle</info>
110111
<info>php %command.full_name% --dump-messages --sort=desc fr</info>
112+
113+
You can dump a tree-like structure using the yaml format with <comment>--as-tree</> flag:
114+
115+
<info>php %command.full_name% --force --output-format=yaml --as-tree=3 en AcmeBundle</info>
116+
<info>php %command.full_name% --force --output-format=yaml --sort=asc --as-tree=3 fr</info>
117+
111118
EOF
112119
)
113120
;
@@ -302,7 +309,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
302309
$bundleTransPath = end($transPaths);
303310
}
304311

305-
$this->writer->write($operation->getResult(), $input->getOption('output-format'), ['path' => $bundleTransPath, 'default_locale' => $this->defaultLocale, 'xliff_version' => $input->getOption('xliff-version')]);
312+
$this->writer->write($operation->getResult(), $input->getOption('output-format'), ['path' => $bundleTransPath, 'default_locale' => $this->defaultLocale, 'xliff_version' => $input->getOption('xliff-version'), 'as_tree' => $input->getOption('as-tree'), 'inline' => $input->getOption('as-tree') ?? 0]);
306313

307314
if (true === $input->getOption('dump-messages')) {
308315
$resultMessage .= ' and translation files were updated';

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ public function testDumpMessagesAndClean()
3232
$this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay());
3333
}
3434

35+
public function testDumpMessagesAsTreeAndClean()
36+
{
37+
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
38+
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--as-tree' => 1]);
39+
$this->assertMatchesRegularExpression('/foo/', $tester->getDisplay());
40+
$this->assertMatchesRegularExpression('/1 message was successfully extracted/', $tester->getDisplay());
41+
}
42+
3543
public function testDumpSortedMessagesAndClean()
3644
{
3745
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]);

0 commit comments

Comments
 (0)
0