Skip to content

Commit 737d1bb

Browse files
committed
Merge pull request #41 from Kunstmaan/fix_translation_import
by default, import the translations from all your own bundles
2 parents f204687 + f773e71 commit 737d1bb

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getConfigTreeBuilder()
3131

3232
->scalarNode('default_bundle')
3333
->cannotBeEmpty()
34-
->defaultValue('kunstmaantranslatorbundle')
34+
->defaultValue('own')
3535
->end()
3636

3737
->scalarNode('cache_dir')

Service/Command/Importer/ImportCommandHandler.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace Kunstmaan\TranslatorBundle\Service\Command\Importer;
44

55
use Kunstmaan\TranslatorBundle\Model\Import\ImportCommand;
6-
use Symfony\Component\Finder\Finder;
6+
use Kunstmaan\TranslatorBundle\Service\Command\AbstractCommandHandler;
77
use Kunstmaan\TranslatorBundle\Service\Exception\TranslationsNotFoundException;
8+
use Symfony\Component\Finder\Finder;
89

910
/**
1011
* Parses an ImportCommand
1112
*/
12-
class ImportCommandHandler extends \Kunstmaan\TranslatorBundle\Service\Command\AbstractCommandHandler
13+
class ImportCommandHandler extends AbstractCommandHandler
1314
{
1415

1516
/**
@@ -58,8 +59,12 @@ public function importGlobalTranslationFiles(ImportCommand $importCommand)
5859
*/
5960
public function importBundleTranslationFiles(ImportCommand $importCommand)
6061
{
61-
if (strtolower($importCommand->getBundle()) == 'all') {
62+
$importBundle = strtolower($importCommand->getBundle());
63+
64+
if ($importBundle == 'all') {
6265
return $this->importAllBundlesTranslationFiles($importCommand);
66+
} elseif ($importBundle == 'own') {
67+
return $this->importOwnBundlesTranslationFiles($importCommand);
6368
}
6469

6570
return $this->importSingleBundleTranslationFiles($importCommand);
@@ -88,6 +93,31 @@ public function importAllBundlesTranslationFiles(ImportCommand $importCommand)
8893
return $imported;
8994
}
9095

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+
91121
/**
92122
* Import all translation files from a single bundle
93123
* @param ImportCommand $importCommand

0 commit comments

Comments
 (0)