public function onRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
$route = $request->attributes->get('_route');
if (strpos($route, 'newscoop_gimme_') !== false || $route == 'newscoop_get_img') {
return;
}
$locale = $event->getRequest()->getLocale();
$cacheKey = $this->cacheService->getCacheKey('oldPlugins_translations_' . count($this->pluginsService->getEnabledPlugins()));
if ($this->cacheService->contains($cacheKey)) {
$files = $this->cacheService->fetch($cacheKey);
} else {
$finder = new Finder();
$extension = $locale . '.yml';
$files = array();
try {
$finder->files()->in(__DIR__ . '/../../../../plugins/*/admin-files/translations');
$finder->files()->name('*.' . $locale . '.yml');
} catch (\InvalidArgumentException $e) {
return;
}
foreach ($finder as $file) {
$domain = substr($file->getFileName(), 0, -1 * strlen($extension) - 1);
$files[$domain] = $file->getRealpath();
}
$this->cacheService->save($cacheKey, $files);
}
try {
if (count($files) > 0) {
$this->translator->addLoader('yaml', new YamlFileLoader());
foreach ($files as $key => $file) {
$this->translator->addResource('yaml', $file, $locale, $key);
}
}
} catch (\InvalidArgumentException $exception) {
throw new \Exception('Plugins directory doesn\'t exist!');
}
}