From 858ba82cd1ba5b902fdc267a53398c277582598d Mon Sep 17 00:00:00 2001 From: Anton Dachauer Date: Sun, 23 Sep 2018 16:08:22 +0200 Subject: [PATCH 1/2] Fixing for running from Controller Using "this->getContainer()" is better as "this->getApplication()" --- Command/ImportTranslationsCommand.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Command/ImportTranslationsCommand.php b/Command/ImportTranslationsCommand.php index 9def8d06..8e4fc3c6 100644 --- a/Command/ImportTranslationsCommand.php +++ b/Command/ImportTranslationsCommand.php @@ -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('Using: ' . $bundle->getName() . ' as bundle to lookup translations files for.'); } @@ -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); } @@ -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); @@ -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('*** Importing ' . $bundle->getName() . '`s translation files from ' . $path . ' ***'); } @@ -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; } From 7d9fed028d5f550bcb3702b37b52f6627275223e Mon Sep 17 00:00:00 2001 From: Anton Dachauer Date: Sun, 23 Sep 2018 16:43:54 +0200 Subject: [PATCH 2/2] fixing typo --- Command/ImportTranslationsCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/ImportTranslationsCommand.php b/Command/ImportTranslationsCommand.php index 8e4fc3c6..9303a380 100644 --- a/Command/ImportTranslationsCommand.php +++ b/Command/ImportTranslationsCommand.php @@ -233,7 +233,7 @@ protected function importBundleTranslationFiles(BundleInterface $bundle, $locale { $path = $bundle->getPath(); if ($global) { - $path = $this->getContainer()->getParameter('kernel.root_dir')) . '/Resources/' . $bundle->getName() . '/translations'; + $path = $this->getContainer()->getParameter('kernel.root_dir') . '/Resources/' . $bundle->getName() . '/translations'; $this->output->writeln('*** Importing ' . $bundle->getName() . '`s translation files from ' . $path . ' ***'); }