Example #1
0
 /**
  * @param array         $locales
  *
  * @return bool
  * @throws \Symfony\Component\Filesystem\Exception\IOException
  * @throws \RuntimeException
  */
 public function dumpTranslations($locales = [])
 {
     if (empty($locales)) {
         $locales[] = $this->defaultLocale;
     }
     $targetPattern = realpath($this->kernelRootDir . '/../web') . $this->router->getRouteCollection()->get($this->jsTranslationRoute)->getPath();
     foreach ($locales as $locale) {
         $target = strtr($targetPattern, array('{_locale}' => $locale));
         $this->logger->info(sprintf('<comment>%s</comment> <info>[file+]</info> %s', date('H:i:s'), basename($target)));
         $content = $this->translationController->renderJsTranslationContent($this->translationDomains, $locale);
         $dirName = dirname($target);
         if (!is_dir($dirName) && true !== @mkdir($dirName, 0777, true)) {
             throw new IOException(sprintf('Failed to create %s', $dirName));
         }
         if (false === @file_put_contents($target, $content)) {
             throw new \RuntimeException('Unable to write file ' . $target);
         }
     }
     return true;
 }