Skip to content

Commit

Permalink
Fixed whitespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
agar committed May 5, 2011
1 parent 2457896 commit bdfc87b
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Command/UpdateTransCommand.php
Expand Up @@ -11,11 +11,11 @@

class UpdateTransCommand extends Command {

/**
* Deafult domain for found trans blocks/filters
*
* @var string
*/
/**
* Deafult domain for found trans blocks/filters
*
* @var string
*/
private $defaultDomain = 'messages';

/**
Expand Down Expand Up @@ -98,9 +98,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$finder = new Finder();
$files = $finder->files()->name('*.' . $input->getArgument('locale') . '.yml')->in($bundleTransPath);
foreach ($files as $file) {
$output->writeln(sprintf(' > parsing translation <comment>%s</comment>', $file->getPathname()));
$domain = substr($file->getFileName(), 0, strrpos($file->getFileName(), $input->getArgument('locale') . '.yml') - 1);
$yml_loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
$output->writeln(sprintf(' > parsing translation <comment>%s</comment>', $file->getPathname()));
$domain = substr($file->getFileName(), 0, strrpos($file->getFileName(), $input->getArgument('locale') . '.yml') - 1);
$yml_loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
$this->messages->addCatalogue($yml_loader->load($file->getPathname(), $input->getArgument('locale'), $domain));
}

Expand All @@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

// load any existing php translation files
$finder = new Finder();
$finder = new Finder();
$files = $finder->files()->name('*.' . $input->getArgument('locale') . '.php')->in($bundleTransPath);
foreach ($files as $file) {
$output->writeln(sprintf(' > parsing translation <comment>%s</comment>', $file->getPathname()));
Expand All @@ -127,8 +127,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
// show compiled list of messages
if($input->getOption('dump-messages') === true){
foreach ($this->messages->getDomains() as $domain) {
$output->writeln(sprintf("\nDisplaying messages for domain <info>%s</info>:\n", $domain));
$output->writeln(\Symfony\Component\Yaml\Yaml::dump($this->messages->all($domain),10));
$output->writeln(sprintf("\nDisplaying messages for domain <info>%s</info>:\n", $domain));
$output->writeln(\Symfony\Component\Yaml\Yaml::dump($this->messages->all($domain),10));
}
}

Expand All @@ -137,17 +137,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln("\nWriting files.\n");
$path = $foundBundle->getPath() . '/Resources/translations/';
if ($input->getOption('output-format') == 'yml') {
$formatter = new \BCC\ExtraToolsBundle\Translation\Formatter\YmlFormatter();
$formatter = new \BCC\ExtraToolsBundle\Translation\Formatter\YmlFormatter();
} elseif ($input->getOption('output-format') == 'php') {
$formatter = new \BCC\ExtraToolsBundle\Translation\Formatter\PhpFormatter();
$formatter = new \BCC\ExtraToolsBundle\Translation\Formatter\PhpFormatter();
} else {
$formatter = new \BCC\ExtraToolsBundle\Translation\Formatter\XliffFormatter($input->getOption('source-lang'));
}
foreach ($this->messages->getDomains() as $domain) {
$file = $domain . '.' . $input->getArgument('locale') . '.' . $input->getOption('output-format');
if (file_exists($path . $file)) {
copy($path . $file, $path . '~' . $file . '.bak');
}
}
$output->writeln(sprintf(' > generating <comment>%s</comment>', $path . $file));
file_put_contents($path . $file, $formatter->format($this->messages->all($domain)));
}
Expand All @@ -163,19 +163,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
private function _crawlNode(\Twig_Node $node)
{
if ($node instanceof \Symfony\Bridge\Twig\Node\TransNode && !$node->getNode('body') instanceof \Twig_Node_Expression_GetAttr) {
// trans block
// trans block
$domain = $node->getNode('domain')->getAttribute('value');
$message = $node->getNode('body')->getAttribute('data');
$this->messages->set($message, $this->prefix.$message, $domain);
} else if ($node instanceof \Twig_Node_Print) {
// trans filter (be carefull of how you chain your filters)
// trans filter (be carefull of how you chain your filters)
$message = $this->_extractMessage($node->getNode('expr'));
$domain = $this->_extractDomain($node->getNode('expr'));
if($message !== null && $domain!== null) {
$this->messages->set($message, $this->prefix.$message, $domain);
}
} else {
// continue crawling
// continue crawling
foreach ($node as $child) {
if ($child != null) {
$this->_crawlNode($child);
Expand All @@ -196,7 +196,7 @@ private function _extractMessage(\Twig_Node $node)
return $this->_extractMessage($node->getNode ('node'));
}
if($node instanceof \Twig_Node_Expression_Constant) {
return $node->getAttribute('value');
return $node->getAttribute('value');
}

return null;
Expand Down

0 comments on commit bdfc87b

Please sign in to comment.