Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[FrameworkBundle] Enabled translation:update for app folder
Changed the Bundle requirement to allow the command to also be executed for the app/Resources
folder of the application, which currently cannot be achieved.
  • Loading branch information
rdohms committed Jul 25, 2014
commit d68af158a314e165ea5827cd4cb773c0595c6cb0
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function configure()
->setName('translation:update')
->setDefinition(array(
new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
new InputArgument('bundle', InputArgument::REQUIRED, 'The bundle where to load the messages'),
new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle where to load the messages, defaults to app/Resources folder', null),
new InputOption(
'prefix', null, InputOption::VALUE_OPTIONAL,
'Override the default prefix', '__'
Expand Down Expand Up @@ -64,13 +64,18 @@ protected function configure()
->setDescription('Updates the translation file')
->setHelp(<<<EOF
The <info>%command.name%</info> command extract translation strings from templates
of a given bundle. It can display them or merge the new ones into the translation files.
of a given bundle or the app folder. It can display them or merge the new ones into the translation files.
When new translation strings are found it can automatically add a prefix to the translation
message.

Example running against a Bundle (AcmeBundle)
<info>php %command.full_name% --dump-messages en AcmeBundle</info>
<info>php %command.full_name% --force --prefix="new_" fr AcmeBundle</info>

Example running against app messages (app/Resources folder)
<info>php %command.full_name% --dump-messages en</info>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a small text before these command to explicitely make a difference between messages coming from a bundle and messages coming from app?

<info>php %command.full_name% --force --prefix="new_" fr</info>

EOF
)
;
Expand Down Expand Up @@ -98,23 +103,33 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}

// Define Root Path to App folder
$rootPath = $this->getApplication()->getKernel()->getRootDir();
$currentName = "app folder";

// Override with provided Bundle info
if (null !== $input->getArgument('bundle')) {
$foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
$rootPath = $foundBundle->getPath();
$currentName = $foundBundle->getName();
}

// get bundle directory
$foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
$bundleTransPath = $foundBundle->getPath().'/Resources/translations';
$output->writeln(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $foundBundle->getName()));
$translationsPath = $rootPath.'/Resources/translations';
$output->writeln(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->writeln('Parsing templates');
$extractor = $this->getContainer()->get('translation.extractor');
$extractor->setPrefix($input->getOption('prefix'));
$extractor->extract($foundBundle->getPath().'/Resources/views/', $extractedCatalogue);
$extractor->extract($rootPath.'/Resources/views/', $extractedCatalogue);

// load any existing messages from the translation files
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
$output->writeln('Loading translation files');
$loader = $this->getContainer()->get('translation.loader');
$loader->loadMessages($bundleTransPath, $currentCatalogue);
$loader->loadMessages($translationsPath, $currentCatalogue);

// process catalogues
$operation = $input->getOption('clean')
Expand Down Expand Up @@ -150,7 +165,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// save the files
if ($input->getOption('force') === true) {
$output->writeln('Writing files');
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath));
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $translationsPath));
}
}
}