Updated the style of the translation commands
This commit is contained in:
parent
ff6d9c1e50
commit
8bcb9fc3f8
@ -207,15 +207,15 @@ EOF
|
|||||||
private function formatState($state)
|
private function formatState($state)
|
||||||
{
|
{
|
||||||
if (self::MESSAGE_MISSING === $state) {
|
if (self::MESSAGE_MISSING === $state) {
|
||||||
return '<error>missing</error>';
|
return '<error> missing </error>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::MESSAGE_UNUSED === $state) {
|
if (self::MESSAGE_UNUSED === $state) {
|
||||||
return '<comment>unused</comment>';
|
return '<comment> unused </comment>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::MESSAGE_EQUALS_FALLBACK === $state) {
|
if (self::MESSAGE_EQUALS_FALLBACK === $state) {
|
||||||
return '<info>fallback</info>';
|
return '<info> fallback </info>';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $state;
|
return $state;
|
||||||
@ -233,7 +233,7 @@ EOF
|
|||||||
|
|
||||||
private function formatId($id)
|
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)
|
private function sanitizeString($string, $length = 40)
|
||||||
|
@ -21,7 +21,8 @@ use Symfony\Component\Console\Input\InputOption;
|
|||||||
use Symfony\Component\Translation\MessageCatalogue;
|
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>
|
* @author Michel Salib <michelsalib@hotmail.com>
|
||||||
*/
|
*/
|
||||||
@ -81,7 +82,7 @@ EOF
|
|||||||
$writer = $this->getContainer()->get('translation.writer');
|
$writer = $this->getContainer()->get('translation.writer');
|
||||||
$supportedFormats = $writer->getFormats();
|
$supportedFormats = $writer->getFormats();
|
||||||
if (!in_array($input->getOption('output-format'), $supportedFormats)) {
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -111,12 +112,12 @@ EOF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->title('Symfony translation update command');
|
$output->title('Translation Messages Extractor and Dumper');
|
||||||
$output->text(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $currentName));
|
$output->comment(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $currentName));
|
||||||
|
|
||||||
// load any messages from templates
|
// load any messages from templates
|
||||||
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
|
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
|
||||||
$output->text('Parsing templates');
|
$output->comment('Parsing templates...');
|
||||||
$extractor = $this->getContainer()->get('translation.extractor');
|
$extractor = $this->getContainer()->get('translation.extractor');
|
||||||
$extractor->setPrefix($input->getOption('prefix'));
|
$extractor->setPrefix($input->getOption('prefix'));
|
||||||
foreach ($transPaths as $path) {
|
foreach ($transPaths as $path) {
|
||||||
@ -128,7 +129,7 @@ EOF
|
|||||||
|
|
||||||
// load any existing messages from the translation files
|
// load any existing messages from the translation files
|
||||||
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
|
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
|
||||||
$output->text('Loading translation files');
|
$output->comment('Loading translation files...');
|
||||||
$loader = $this->getContainer()->get('translation.loader');
|
$loader = $this->getContainer()->get('translation.loader');
|
||||||
foreach ($transPaths as $path) {
|
foreach ($transPaths as $path) {
|
||||||
$path .= 'translations';
|
$path .= 'translations';
|
||||||
@ -144,18 +145,22 @@ EOF
|
|||||||
|
|
||||||
// Exit if no messages found.
|
// Exit if no messages found.
|
||||||
if (!count($operation->getDomains())) {
|
if (!count($operation->getDomains())) {
|
||||||
$output->warning('No translation found.');
|
$output->warning('No translation messages were found.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// show compiled list of messages
|
// show compiled list of messages
|
||||||
if ($input->getOption('dump-messages') === true) {
|
if (true === $input->getOption('dump-messages')) {
|
||||||
|
$extractedMessagesCount = 0;
|
||||||
$output->newLine();
|
$output->newLine();
|
||||||
foreach ($operation->getDomains() as $domain) {
|
foreach ($operation->getDomains() as $domain) {
|
||||||
$output->section(sprintf('Displaying messages for domain <info>%s</info>:', $domain));
|
|
||||||
$newKeys = array_keys($operation->getNewMessages($domain));
|
$newKeys = array_keys($operation->getNewMessages($domain));
|
||||||
$allKeys = array_keys($operation->getMessages($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(
|
$output->listing(array_merge(
|
||||||
array_diff($allKeys, $newKeys),
|
array_diff($allKeys, $newKeys),
|
||||||
array_map(function ($id) {
|
array_map(function ($id) {
|
||||||
@ -165,11 +170,15 @@ EOF
|
|||||||
return sprintf('<fg=red>%s</>', $id);
|
return sprintf('<fg=red>%s</>', $id);
|
||||||
}, array_keys($operation->getObsoleteMessages($domain)))
|
}, array_keys($operation->getObsoleteMessages($domain)))
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$extractedMessagesCount += $domainMessagesCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($input->getOption('output-format') == 'xlf') {
|
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) {
|
if ($input->getOption('no-backup') === true) {
|
||||||
@ -178,7 +187,7 @@ EOF
|
|||||||
|
|
||||||
// save the files
|
// save the files
|
||||||
if ($input->getOption('force') === true) {
|
if ($input->getOption('force') === true) {
|
||||||
$output->text('Writing files');
|
$output->comment('Writing files...');
|
||||||
|
|
||||||
$bundleTransPath = false;
|
$bundleTransPath = false;
|
||||||
foreach ($transPaths as $path) {
|
foreach ($transPaths as $path) {
|
||||||
@ -191,9 +200,14 @@ EOF
|
|||||||
if ($bundleTransPath) {
|
if ($bundleTransPath) {
|
||||||
$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('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($resultMessage);
|
||||||
$output->success('Success');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user