|
3 | 3 | namespace Kunstmaan\TranslatorBundle\Service\Command\Importer; |
4 | 4 |
|
5 | 5 | use Kunstmaan\TranslatorBundle\Model\Import\ImportCommand; |
6 | | -use Symfony\Component\Finder\Finder; |
| 6 | +use Kunstmaan\TranslatorBundle\Service\Command\AbstractCommandHandler; |
7 | 7 | use Kunstmaan\TranslatorBundle\Service\Exception\TranslationsNotFoundException; |
| 8 | +use Symfony\Component\Finder\Finder; |
8 | 9 |
|
9 | 10 | /** |
10 | 11 | * Parses an ImportCommand |
11 | 12 | */ |
12 | | -class ImportCommandHandler extends \Kunstmaan\TranslatorBundle\Service\Command\AbstractCommandHandler |
| 13 | +class ImportCommandHandler extends AbstractCommandHandler |
13 | 14 | { |
14 | 15 |
|
15 | 16 | /** |
@@ -58,8 +59,12 @@ public function importGlobalTranslationFiles(ImportCommand $importCommand) |
58 | 59 | */ |
59 | 60 | public function importBundleTranslationFiles(ImportCommand $importCommand) |
60 | 61 | { |
61 | | - if (strtolower($importCommand->getBundle()) == 'all') { |
| 62 | + $importBundle = strtolower($importCommand->getBundle()); |
| 63 | + |
| 64 | + if ($importBundle == 'all') { |
62 | 65 | return $this->importAllBundlesTranslationFiles($importCommand); |
| 66 | + } elseif ($importBundle == 'own') { |
| 67 | + return $this->importOwnBundlesTranslationFiles($importCommand); |
63 | 68 | } |
64 | 69 |
|
65 | 70 | return $this->importSingleBundleTranslationFiles($importCommand); |
@@ -88,6 +93,31 @@ public function importAllBundlesTranslationFiles(ImportCommand $importCommand) |
88 | 93 | return $imported; |
89 | 94 | } |
90 | 95 |
|
| 96 | + /** |
| 97 | + * Import all translation files from your own registered bundles (in src/ directory) |
| 98 | + * @param ImportCommand $importCommand |
| 99 | + * @return int The total number of imported files |
| 100 | + */ |
| 101 | + public function importOwnBundlesTranslationFiles(ImportCommand $importCommand) |
| 102 | + { |
| 103 | + $imported = 0; |
| 104 | + $srcDir = dirname($this->kernel->getRootDir()) . '/src'; |
| 105 | + |
| 106 | + foreach($this->kernel->getBundles() as $name => $bundle) { |
| 107 | + if (strpos($bundle->getPath(), $srcDir) !== false) { |
| 108 | + $importCommand->setBundle(strtolower($name)); |
| 109 | + |
| 110 | + try { |
| 111 | + $imported += $this->importSingleBundleTranslationFiles($importCommand); |
| 112 | + } catch (TranslationsNotFoundException $e) { |
| 113 | + continue; |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + return $imported; |
| 119 | + } |
| 120 | + |
91 | 121 | /** |
92 | 122 | * Import all translation files from a single bundle |
93 | 123 | * @param ImportCommand $importCommand |
|
0 commit comments