/**
  * Export the translations
  *
  * @param Translations $translations The translations to export
  * @param array        $bundles List of bundles (empty array: all)
  * @param array        $domains List of domains (empty array: all)
  * @param array        $locales List of locales (empty array: all)
  * @param string       $filename The filename to export
  * @return Response
  * @throws ExporterException
  */
 public function export(Translations $translations, array $bundles = array(), array $domains = array(), array $locales = array(), $filename = null)
 {
     // Current date and time
     $now = new \DateTime();
     // Validate the params
     if (!count($bundles)) {
         $bundles = $translations->getBundles();
     }
     if (!count($domains)) {
         $domains = $translations->getDomains();
     }
     if (!count($locales)) {
         $locales = $translations->getLocales();
     }
     if (null == $filename) {
         $filename = 'davamigo_translator_' . $now->format('Y-m-d_H-i-s') . '.yml';
     }
     // Create the Yaml file
     $buffer = '';
     foreach ($bundles as $bundle) {
         foreach ($domains as $domain) {
             foreach ($locales as $locale) {
                 $messages = $translations->getMessages($bundle, $domain, $locale);
                 if (count($messages) > 0) {
                     $buffer .= '# ' . str_repeat('-', 80) . PHP_EOL;
                     $buffer .= '# ' . $bundle . '/' . $domain . '.' . $locale . '.yml' . PHP_EOL;
                     try {
                         $data = $this->prepareYamlArray($messages);
                         $buffer .= $this->yamlDumper->dump($data, 100);
                     } catch (InvalidResourceException $exc) {
                         $buffer .= $exc->getMessage();
                     }
                     $buffer .= PHP_EOL . PHP_EOL;
                 }
             }
         }
     }
     // Create the response
     return $this->createResponse($buffer, $filename);
 }
 /**
  * Export the translations
  *
  * @param Translations $translations The translations to export
  * @param array        $bundles List of bundles (empty array: all)
  * @param array        $domains List of domains (empty array: all)
  * @param array        $locales List of locales (empty array: all)
  * @param string       $filename The filename to export
  * @return Response
  * @throws ExporterException
  */
 public function export(Translations $translations, array $bundles = array(), array $domains = array(), array $locales = array(), $filename = null)
 {
     // Current date and time
     $now = new \DateTime();
     // Validate the params
     if (!count($bundles)) {
         $bundles = $translations->getBundles();
     }
     if (!count($domains)) {
         $domains = $translations->getDomains();
     }
     if (!count($locales)) {
         $locales = $translations->getLocales();
     }
     if (null == $filename) {
         $filename = 'davamigo_translator_' . $now->format('Y-m-d_H-i-s') . '.xls';
     }
     // Create the Excel object
     $excelObj = $this->phpExcelFactory->createPHPExcelObject();
     if (null == $excelObj) {
         throw new ExporterException('Can\'t create the Excel object.');
     }
     // Se the Excel properties
     $excelObj->getProperties()->setTitle('Davamigo Symfony Translations')->setDescription('Davamigo Symfony Translations')->setCompany('Davamigo')->setCreator('Davamigo')->setLastModifiedBy('Davamigo')->setCreated($now->getTimestamp())->setModified($now->getTimestamp());
     // Create active sheet
     $excelObj->setActiveSheetIndex(0);
     $worksheet = $excelObj->getSheet(0);
     $worksheet->setTitle('Translations');
     // Create the Excel header (first row)
     $row = 1;
     $col = 0;
     $headers = array_merge(static::$fixedHeader, $locales);
     foreach ($headers as $string) {
         $cell = $worksheet->getCellByColumnAndRow($col, $row);
         $cell->setValue($string);
         $style = $worksheet->getStyle($cell->getCoordinate());
         $style->applyFromArray(static::$headerCellStyle);
         ++$col;
     }
     foreach ($bundles as $bundle) {
         foreach ($domains as $domain) {
             $resources = $translations->getResources($bundle, $domain);
             foreach ($resources as $resource) {
                 //
                 $content = array($bundle, $domain, $resource);
                 foreach ($locales as $locale) {
                     $content[] = $translations->getTranslation($bundle, $domain, $locale, $resource);
                 }
                 ++$row;
                 $col = 0;
                 foreach ($content as $string) {
                     $cell = $worksheet->getCellByColumnAndRow($col, $row);
                     $cell->setValue($string);
                     $style = $worksheet->getStyle($cell->getCoordinate());
                     $style->applyFromArray(static::$textCellStyle);
                     ++$col;
                 }
             }
         }
     }
     // Auto-size all columns
     for ($col = 0; $col < count($headers); ++$col) {
         $dimension = $worksheet->getColumnDimensionByColumn($col);
         $dimension->setAutoSize(true);
     }
     // Create the response
     return $this->createResponse($excelObj, $filename);
 }