Beispiel #1
0
 /**
  * Generate language pack
  *
  * @param string $dictionaryPath
  * @param string $packPath
  * @param string $locale
  * @param string $mode One of const of WriterInterface::MODE_
  * @param bool $allowDuplicates
  * @return void
  * @throws \RuntimeException
  */
 public function generate($dictionaryPath, $packPath, $locale, $mode = WriterInterface::MODE_REPLACE, $allowDuplicates = false)
 {
     $locale = $this->factory->createLocale($locale);
     $dictionary = $this->dictionaryLoader->load($dictionaryPath);
     if (!count($dictionary->getPhrases())) {
         throw new \UnexpectedValueException('No phrases have been found by the specified path.');
     }
     if (!$allowDuplicates && ($duplicates = $dictionary->getDuplicates())) {
         throw new \RuntimeException("Duplicated translation is found, but it is not allowed.\n" . $this->createDuplicatesPhrasesError($duplicates));
     }
     $this->packWriter->write($dictionary, $packPath, $locale, $mode);
 }