Merge branch '2.7'
* 2.7: Fix composer.json dependencies [Translation][Profiler] reduce memory usage for collected messages. [FrameworkBundle] Enable translation debugging in directories Conflicts: src/Symfony/Bridge/Twig/composer.json src/Symfony/Bundle/SecurityBundle/composer.json src/Symfony/Bundle/TwigBundle/composer.json src/Symfony/Component/Form/composer.json
This commit is contained in:
commit
48522b8483
@ -41,16 +41,16 @@ class TranslationDebugCommand extends ContainerAwareCommand
|
|||||||
->setName('debug:translation')
|
->setName('debug:translation')
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
|
new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
|
||||||
new InputArgument('bundle', InputArgument::REQUIRED, 'The bundle name'),
|
new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle name or directory where to load the messages, defaults to app/Resources folder'),
|
||||||
new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'The messages domain'),
|
new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'The messages domain'),
|
||||||
new InputOption('only-missing', null, InputOption::VALUE_NONE, 'Displays only missing messages'),
|
new InputOption('only-missing', null, InputOption::VALUE_NONE, 'Displays only missing messages'),
|
||||||
new InputOption('only-unused', null, InputOption::VALUE_NONE, 'Displays only unused messages'),
|
new InputOption('only-unused', null, InputOption::VALUE_NONE, 'Displays only unused messages'),
|
||||||
))
|
))
|
||||||
->setDescription('Displays translation messages informations')
|
->setDescription('Displays translation messages information')
|
||||||
->setHelp(<<<EOF
|
->setHelp(<<<EOF
|
||||||
The <info>%command.name%</info> command helps finding unused or missing translation
|
The <info>%command.name%</info> command helps finding unused or missing translation
|
||||||
messages and comparing them with the fallback ones by inspecting the
|
messages and comparing them with the fallback ones by inspecting the
|
||||||
templates and translation files of a given bundle.
|
templates and translation files of a given bundle or the app folder.
|
||||||
|
|
||||||
You can display information about bundle translations in a specific locale:
|
You can display information about bundle translations in a specific locale:
|
||||||
|
|
||||||
@ -68,6 +68,10 @@ You can only display unused messages:
|
|||||||
|
|
||||||
<info>php %command.full_name% --only-unused en AcmeDemoBundle</info>
|
<info>php %command.full_name% --only-unused en AcmeDemoBundle</info>
|
||||||
|
|
||||||
|
You can display information about app translations in a specific locale:
|
||||||
|
|
||||||
|
<info>php %command.full_name% en</info>
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
@ -80,17 +84,39 @@ EOF
|
|||||||
{
|
{
|
||||||
$locale = $input->getArgument('locale');
|
$locale = $input->getArgument('locale');
|
||||||
$domain = $input->getOption('domain');
|
$domain = $input->getOption('domain');
|
||||||
$bundle = $this->getContainer()->get('kernel')->getBundle($input->getArgument('bundle'));
|
|
||||||
$loader = $this->getContainer()->get('translation.loader');
|
$loader = $this->getContainer()->get('translation.loader');
|
||||||
|
$kernel = $this->getContainer()->get('kernel');
|
||||||
|
|
||||||
|
// Define Root Path to App folder
|
||||||
|
$rootPath = $kernel->getRootDir();
|
||||||
|
|
||||||
|
// Override with provided Bundle info
|
||||||
|
if (null !== $input->getArgument('bundle')) {
|
||||||
|
try {
|
||||||
|
$rootPath = $kernel->getBundle($input->getArgument('bundle'))->getPath();
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
// such a bundle does not exist, so treat the argument as path
|
||||||
|
$rootPath = $input->getArgument('bundle');
|
||||||
|
|
||||||
|
if (!is_dir($rootPath)) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $rootPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// get bundle directory
|
||||||
|
$translationsPath = $rootPath.'/Resources/translations';
|
||||||
|
|
||||||
// Extract used messages
|
// Extract used messages
|
||||||
$extractedCatalogue = new MessageCatalogue($locale);
|
$extractedCatalogue = new MessageCatalogue($locale);
|
||||||
$this->getContainer()->get('translation.extractor')->extract($bundle->getPath().'/Resources/views', $extractedCatalogue);
|
if (is_dir($rootPath.'/Resources/views')) {
|
||||||
|
$this->getContainer()->get('translation.extractor')->extract($rootPath.'/Resources/views', $extractedCatalogue);
|
||||||
|
}
|
||||||
|
|
||||||
// Load defined messages
|
// Load defined messages
|
||||||
$currentCatalogue = new MessageCatalogue($locale);
|
$currentCatalogue = new MessageCatalogue($locale);
|
||||||
if (is_dir($bundle->getPath().'/Resources/translations')) {
|
if (is_dir($translationsPath)) {
|
||||||
$loader->loadMessages($bundle->getPath().'/Resources/translations', $currentCatalogue);
|
$loader->loadMessages($translationsPath, $currentCatalogue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge defined and extracted messages to get all message ids
|
// Merge defined and extracted messages to get all message ids
|
||||||
@ -123,7 +149,7 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
$fallbackCatalogue = new MessageCatalogue($fallbackLocale);
|
$fallbackCatalogue = new MessageCatalogue($fallbackLocale);
|
||||||
$loader->loadMessages($bundle->getPath().'/Resources/translations', $fallbackCatalogue);
|
$loader->loadMessages($translationsPath, $fallbackCatalogue);
|
||||||
$fallbackCatalogues[] = $fallbackCatalogue;
|
$fallbackCatalogues[] = $fallbackCatalogue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class TranslationUpdateCommand extends ContainerAwareCommand
|
|||||||
->setName('translation:update')
|
->setName('translation:update')
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
|
new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
|
||||||
new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle where to load the messages, defaults to app/Resources folder', null),
|
new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle name or directory where to load the messages, defaults to app/Resources folder'),
|
||||||
new InputOption('prefix', null, InputOption::VALUE_OPTIONAL, 'Override the default prefix', '__'),
|
new InputOption('prefix', null, InputOption::VALUE_OPTIONAL, 'Override the default prefix', '__'),
|
||||||
new InputOption('output-format', null, InputOption::VALUE_OPTIONAL, 'Override the default output format', 'yml'),
|
new InputOption('output-format', null, InputOption::VALUE_OPTIONAL, 'Override the default output format', 'yml'),
|
||||||
new InputOption('dump-messages', null, InputOption::VALUE_NONE, 'Should the messages be dumped in the console'),
|
new InputOption('dump-messages', null, InputOption::VALUE_NONE, 'Should the messages be dumped in the console'),
|
||||||
@ -83,16 +83,27 @@ EOF
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
$kernel = $this->getContainer()->get('kernel');
|
||||||
|
|
||||||
// Define Root Path to App folder
|
// Define Root Path to App folder
|
||||||
$rootPath = $this->getApplication()->getKernel()->getRootDir();
|
$rootPath = $kernel->getRootDir();
|
||||||
$currentName = "app folder";
|
$currentName = "app folder";
|
||||||
|
|
||||||
// Override with provided Bundle info
|
// Override with provided Bundle info
|
||||||
if (null !== $input->getArgument('bundle')) {
|
if (null !== $input->getArgument('bundle')) {
|
||||||
$foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
|
try {
|
||||||
|
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
|
||||||
$rootPath = $foundBundle->getPath();
|
$rootPath = $foundBundle->getPath();
|
||||||
$currentName = $foundBundle->getName();
|
$currentName = $foundBundle->getName();
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
// such a bundle does not exist, so treat the argument as path
|
||||||
|
$rootPath = $input->getArgument('bundle');
|
||||||
|
$currentName = $rootPath;
|
||||||
|
|
||||||
|
if (!is_dir($rootPath)) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $rootPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get bundle directory
|
// get bundle directory
|
||||||
|
@ -37,8 +37,7 @@
|
|||||||
"symfony/yaml": "~2.7|~3.0",
|
"symfony/yaml": "~2.7|~3.0",
|
||||||
"symfony/expression-language": "~2.7|~3.0",
|
"symfony/expression-language": "~2.7|~3.0",
|
||||||
"doctrine/doctrine-bundle": "~1.2",
|
"doctrine/doctrine-bundle": "~1.2",
|
||||||
"twig/twig": "~1.12",
|
"twig/twig": "~1.12"
|
||||||
"ircmaxell/password-compat": "~1.0"
|
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": { "Symfony\\Bundle\\SecurityBundle\\": "" }
|
"psr-0": { "Symfony\\Bundle\\SecurityBundle\\": "" }
|
||||||
|
@ -95,21 +95,22 @@ class TranslationDataCollector extends DataCollector implements LateDataCollecto
|
|||||||
|
|
||||||
private function sanitizeCollectedMessages($messages)
|
private function sanitizeCollectedMessages($messages)
|
||||||
{
|
{
|
||||||
|
$result = array();
|
||||||
foreach ($messages as $key => $message) {
|
foreach ($messages as $key => $message) {
|
||||||
$messages[$key]['translation'] = $this->sanitizeString($message['translation']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_reduce($messages, function ($result, $message) {
|
|
||||||
$messageId = $message['locale'].$message['domain'].$message['id'];
|
$messageId = $message['locale'].$message['domain'].$message['id'];
|
||||||
|
|
||||||
if (!isset($result[$messageId])) {
|
if (!isset($result[$messageId])) {
|
||||||
$message['count'] = 1;
|
$message['count'] = 1;
|
||||||
|
$messages[$key]['translation'] = $this->sanitizeString($message['translation']);
|
||||||
$result[$messageId] = $message;
|
$result[$messageId] = $message;
|
||||||
} else {
|
} else {
|
||||||
$result[$messageId]['count']++;
|
$result[$messageId]['count']++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($messages[$key]);
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}, array());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function computeCount($messages)
|
private function computeCount($messages)
|
||||||
|
Reference in New Issue
Block a user