Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing for running from Controller #336

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 8 additions & 6 deletions Command/ImportTranslationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ protected function execute(InputInterface $input, OutputInterface $output)

$bundleName = $this->input->getArgument('bundle');
if ($bundleName) {
$bundle = $this->getApplication()->getKernel()->getBundle($bundleName);
$bundle = $this
->getContainer()->get('kernel')
->getBundle($bundleName);

if (Kernel::VERSION_ID < 40000 && null !== $bundle->getParent()) {
// due to symfony's bundle inheritance if a bundle has a parent it is fetched first.
// so we tell getBundle to NOT fetch the first if a parent is present
$bundles = $this->getApplication()->getKernel()->getBundle($bundle->getParent(), false);
$bundles = $this->getContainer()->get('kernel')->getBundle($bundle->getParent(), false);
$bundle = $bundles[1];
$this->output->writeln('<info>Using: ' . $bundle->getName() . ' as bundle to lookup translations files for.');
}
Expand Down Expand Up @@ -199,7 +201,7 @@ protected function importComponentTranslationFiles(array $locales, array $domain
*/
protected function importAppTranslationFiles(array $locales, array $domains)
{
$finder = $this->findTranslationsFiles($this->getApplication()->getKernel()->getRootDir(), $locales, $domains);
$finder = $this->findTranslationsFiles($this->getContainer()->getParameter('kernel.root_dir'), $locales, $domains);
$this->importTranslationFiles($finder);
}

Expand All @@ -212,7 +214,7 @@ protected function importAppTranslationFiles(array $locales, array $domains)
*/
protected function importBundlesTranslationFiles(array $locales, array $domains, $global = false)
{
$bundles = $this->getApplication()->getKernel()->getBundles();
$bundles = $this->getContainer()->get('kernel')->getBundles();

foreach ($bundles as $bundle) {
$this->importBundleTranslationFiles($bundle, $locales, $domains, $global);
Expand All @@ -231,7 +233,7 @@ protected function importBundleTranslationFiles(BundleInterface $bundle, $locale
{
$path = $bundle->getPath();
if ($global) {
$path = $this->getApplication()->getKernel()->getRootDir() . '/Resources/' . $bundle->getName() . '/translations';
$path = $this->getContainer()->getParameter('kernel.root_dir') . '/Resources/' . $bundle->getName() . '/translations';
$this->output->writeln('<info>*** Importing ' . $bundle->getName() . '`s translation files from ' . $path . ' ***</info>');
}

Expand Down Expand Up @@ -285,7 +287,7 @@ protected function findTranslationsFiles($path, array $locales, array $domains,
}

if (true === $autocompletePath) {
$dir = (0 === strpos($path, $this->getApplication()->getKernel()->getRootDir() . '/Resources')) ? $path : $path . '/Resources/translations';
$dir = (0 === strpos($path, $this->getContainer()->getParameter('kernel.root_dir') . '/Resources')) ? $path : $path . '/Resources/translations';
} else {
$dir = $path;
}
Expand Down