Skip to content

Commit

Permalink
minor #15969 Updated the style of the translation commands (javieregu…
Browse files Browse the repository at this point in the history
…iluz)

This PR was squashed before being merged into the 2.8 branch (closes #15969).

Discussion
----------

Updated the style of the translation commands

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

@ogizanagi did a great job updating the styles of these commands. This is just a bit of tweaking here and there:

(Left = old; Right = new)

![comparison_1](https://cloud.githubusercontent.com/assets/73419/10136622/b2d049d2-65f5-11e5-9efe-ae74d546298d.png)

![comparison_2](https://cloud.githubusercontent.com/assets/73419/10136625/b8f96e24-65f5-11e5-8726-f092fc10ac38.png)

![comparison_3](https://cloud.githubusercontent.com/assets/73419/10136626/bb34a6cc-65f5-11e5-8312-0f084f04f0df.png)

![comparison_4](https://cloud.githubusercontent.com/assets/73419/10136630/bd851fd8-65f5-11e5-8ef0-71cce64fd2d7.png)

![comparison_5](https://cloud.githubusercontent.com/assets/73419/10136635/bf6173e2-65f5-11e5-9a25-8f04664cfe5a.png)

Commits
-------

8bcb9fc Updated the style of the translation commands
  • Loading branch information
fabpot committed Oct 1, 2015
2 parents 559554e + 8bcb9fc commit bee1faa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
Expand Up @@ -207,15 +207,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
private function formatState($state)
{
if (self::MESSAGE_MISSING === $state) {
return '<error>missing</error>';
return '<error> missing </error>';
}

if (self::MESSAGE_UNUSED === $state) {
return '<comment>unused</comment>';
return '<comment> unused </comment>';
}

if (self::MESSAGE_EQUALS_FALLBACK === $state) {
return '<info>fallback</info>';
return '<info> fallback </info>';
}

return $state;
Expand All @@ -233,7 +233,7 @@ private function formatStates(array $states)

private function formatId($id)
{
return sprintf('<fg=cyan;options=bold>%s</fg=cyan;options=bold>', $id);
return sprintf('<fg=cyan;options=bold>%s</>', $id);
}

private function sanitizeString($string, $length = 40)
Expand Down
Expand Up @@ -21,7 +21,8 @@
use Symfony\Component\Translation\MessageCatalogue;

/**
* A command that parse templates to extract translation messages and add them into the translation files.
* A command that parses templates to extract translation messages and adds them
* into the translation files.
*
* @author Michel Salib <michelsalib@hotmail.com>
*/
Expand Down Expand Up @@ -81,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$writer = $this->getContainer()->get('translation.writer');
$supportedFormats = $writer->getFormats();
if (!in_array($input->getOption('output-format'), $supportedFormats)) {
$output->error(array('Wrong output format', 'Supported formats are '.implode(', ', $supportedFormats).'.'));
$output->error(array('Wrong output format', 'Supported formats are: '.implode(', ', $supportedFormats).'.'));

return 1;
}
Expand Down Expand Up @@ -111,12 +112,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

$output->title('Symfony translation update command');
$output->text(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $currentName));
$output->title('Translation Messages Extractor and Dumper');
$output->comment(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $currentName));

// load any messages from templates
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
$output->text('Parsing templates');
$output->comment('Parsing templates...');
$extractor = $this->getContainer()->get('translation.extractor');
$extractor->setPrefix($input->getOption('prefix'));
foreach ($transPaths as $path) {
Expand All @@ -128,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// load any existing messages from the translation files
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
$output->text('Loading translation files');
$output->comment('Loading translation files...');
$loader = $this->getContainer()->get('translation.loader');
foreach ($transPaths as $path) {
$path .= 'translations';
Expand All @@ -144,18 +145,22 @@ protected function execute(InputInterface $input, OutputInterface $output)

// Exit if no messages found.
if (!count($operation->getDomains())) {
$output->warning('No translation found.');
$output->warning('No translation messages were found.');

return;
}

// show compiled list of messages
if ($input->getOption('dump-messages') === true) {
if (true === $input->getOption('dump-messages')) {
$extractedMessagesCount = 0;
$output->newLine();
foreach ($operation->getDomains() as $domain) {
$output->section(sprintf('Displaying messages for domain <info>%s</info>:', $domain));
$newKeys = array_keys($operation->getNewMessages($domain));
$allKeys = array_keys($operation->getMessages($domain));
$domainMessagesCount = count($newKeys) + count($allKeys);

$output->section(sprintf('Messages extracted for domain "<info>%s</info>" (%d messages)', $domain, $domainMessagesCount));

$output->listing(array_merge(
array_diff($allKeys, $newKeys),
array_map(function ($id) {
Expand All @@ -165,11 +170,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
return sprintf('<fg=red>%s</>', $id);
}, array_keys($operation->getObsoleteMessages($domain)))
));

$extractedMessagesCount += $domainMessagesCount;
}

if ($input->getOption('output-format') == 'xlf') {
$output->writeln('Xliff output version is <info>1.2</info>');
$output->comment('Xliff output version is <info>1.2</info>');
}

$resultMessage = sprintf('%d messages were successfully extracted', $extractedMessagesCount);
}

if ($input->getOption('no-backup') === true) {
Expand All @@ -178,7 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// save the files
if ($input->getOption('force') === true) {
$output->text('Writing files');
$output->comment('Writing files...');

$bundleTransPath = false;
foreach ($transPaths as $path) {
Expand All @@ -191,9 +200,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($bundleTransPath) {
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath, 'default_locale' => $this->getContainer()->getParameter('kernel.default_locale')));
}

if (true === $input->getOption('dump-messages')) {
$resultMessage .= ' and translation files were updated.';
} else {
$resultMessage = 'Translation files were successfully updated.';
}
}

$output->newLine();
$output->success('Success');
$output->success($resultMessage);
}
}

0 comments on commit bee1faa

Please sign in to comment.