Skip to content

Commit

Permalink
Merge c8e89c7 into 473afb3
Browse files Browse the repository at this point in the history
  • Loading branch information
acrobat committed Mar 10, 2019
2 parents 473afb3 + c8e89c7 commit 876a3bf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
Expand Up @@ -7,6 +7,7 @@
use Kunstmaan\TranslatorBundle\Service\Exception\TranslationsNotFoundException;
use Kunstmaan\TranslatorBundle\Service\TranslationFileExplorer;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\Kernel;

/**
* Parses an ImportCommand
Expand Down Expand Up @@ -52,8 +53,10 @@ public function executeImportCommand(ImportCommand $importCommand)
*/
private function importGlobalTranslationFiles(ImportCommand $importCommand)
{
$baseDir = Kernel::VERSION_ID >= 40000 ? '' : '/app';
$translationsDir = Kernel::VERSION_ID >= 40000 ? 'translations' : null;
$locales = $this->determineLocalesToImport($importCommand);
$finder = $this->translationFileExplorer->find($this->kernel->getRootDir(), $locales);
$finder = $this->translationFileExplorer->find($this->kernel->getProjectDir() . $baseDir, $locales, $translationsDir);

return $this->importTranslationFiles($finder, $importCommand->getForce());
}
Expand Down Expand Up @@ -90,6 +93,10 @@ private function importAllBundlesTranslationFiles(ImportCommand $importCommand)
$bundles = array_map('strtolower', array_keys($this->kernel->getBundles()));
$imported = 0;

if (Kernel::VERSION_ID >= 40000) {
$imported += $this->importSf4TranslationFiles($importCommand);
}

foreach ($bundles as $bundle) {
$importCommand->setDefaultBundle($bundle);

Expand All @@ -112,6 +119,10 @@ private function importAllBundlesTranslationFiles(ImportCommand $importCommand)
*/
private function importOwnBundlesTranslationFiles(ImportCommand $importCommand)
{
if (Kernel::VERSION_ID >= 40000) {
return $this->importSf4TranslationFiles($importCommand);
}

$imported = 0;
$srcDir = dirname($this->kernel->getRootDir()) . '/src';

Expand Down Expand Up @@ -246,4 +257,15 @@ public function setImporter($importer)
{
$this->importer = $importer;
}

private function importSf4TranslationFiles($importCommand)
{
$finder = $this->translationFileExplorer->find($this->kernel->getProjectDir(), $this->determineLocalesToImport($importCommand), 'translations');

if ($finder === null) {
return 0;
}

return $this->importTranslationFiles($finder, $importCommand->getForce());
}
}
Expand Up @@ -29,11 +29,12 @@ class TranslationFileExplorer
*
* @return \Symfony\Component\Finder\Finder
*/
public function find($path, array $locales)
public function find($path, array $locales, $translationDirectory = null)
{
$finder = new Finder();
$translationDirectory = $translationDirectory ?? $this->defaultTranslationFolder;

$exploreDir = $path . '/' . $this->defaultTranslationFolder;
$exploreDir = $path . '/' . $translationDirectory;

if (is_dir($exploreDir)) {
$finder->files()
Expand Down
@@ -0,0 +1,4 @@
headers:
frontpage: "FrontPage"
homepage: "Hell Yeah"
sitemap: Sitemap
@@ -0,0 +1,4 @@
headers:
frontpage: "Voorste pagina"
homepage: "Hallo"
sitemap: website skelet
@@ -0,0 +1,3 @@
newdomain:
name: "a new domain"
description: "this domain can be loaded into the database, of not yet exists"

0 comments on commit 876a3bf

Please sign in to comment.