Skip to content

Commit

Permalink
Merge 9c22d80 into bfc666f
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Jan 12, 2018
2 parents bfc666f + 9c22d80 commit 0a4b795
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/DI/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,14 @@ public function beforeCompile()
continue;
}

$config['dirs'] = array_merge($config['dirs'], array_values($extension->getTranslationResources()));
$config['dirs'] = array_merge($config['dirs'], $extension->getTranslationResources());
}

$config['dirs'] = array_map(function ($dir) {
return str_replace((DIRECTORY_SEPARATOR === '/') ? '\\' : '/', DIRECTORY_SEPARATOR, $dir);
}, $config['dirs']);

$dirs = array_values(array_filter($config['dirs'], Callback::closure('is_dir')));
$dirs = array_filter($config['dirs'], Callback::closure('is_dir'));
if (count($dirs) > 0) {
foreach ($dirs as $dir) {
$builder->addDependency($dir);
Expand Down Expand Up @@ -378,19 +378,32 @@ protected function loadResourcesFromDirs($dirs)
return '*.*.' . $value;
}, array_keys($this->loaders));

foreach (Finder::findFiles($mask)->from($dirs) as $file) {
/** @var \SplFileInfo $file */
if (!preg_match('~^(?P<domain>.*?)\.(?P<locale>[^\.]+)\.(?P<format>[^\.]+)$~', $file->getFilename(), $m)) {
continue;
}

if ($whitelistRegexp && !preg_match($whitelistRegexp, $m['locale']) && $builder->parameters['productionMode']) {
continue; // ignore in production mode, there is no need to pass the ignored resources
foreach ($dirs as $baseDomain => $dir) {
foreach (Finder::findFiles($mask)->from($dir) as $file) {
/** @var \SplFileInfo $file */
if (!preg_match('~^(?P<domain>.*?)\.(?P<locale>[^\.]+)\.(?P<format>[^\.]+)$~', $file->getFilename(), $m)) {
continue;
}

$relativePath = str_replace($dir, '', $file->getPath());
if ($relativePath !== '') {
$foldersDomain = str_replace(DIRECTORY_SEPARATOR, '.', $relativePath);
$foldersDomain = ltrim($foldersDomain, '.');
$m['domain'] = $foldersDomain . '.' . $m['domain'];
}

if (is_string($baseDomain)) {
$m['domain'] = $baseDomain . '.' . $m['domain'];
}

if ($whitelistRegexp && !preg_match($whitelistRegexp, $m['locale']) && $builder->parameters['productionMode']) {
continue; // ignore in production mode, there is no need to pass the ignored resources
}

$this->validateResource($m['format'], $file->getPathname(), $m['locale'], $m['domain']);
$translator->addSetup('addResource', [$m['format'], $file->getPathname(), $m['locale'], $m['domain']]);
$builder->addDependency($file->getPathname());
}

$this->validateResource($m['format'], $file->getPathname(), $m['locale'], $m['domain']);
$translator->addSetup('addResource', [$m['format'], $file->getPathname(), $m['locale'], $m['domain']]);
$builder->addDependency($file->getPathname());
}
}

Expand Down

0 comments on commit 0a4b795

Please sign in to comment.