Example #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);
 }
 public function testGenerateWithNotAllowedDuplicatesAndDuplicatesExist()
 {
     $error = "Duplicated translation is found, but it is not allowed.\n" . "The phrase \"phrase1\" is translated differently in 1 places.\n" . "The phrase \"phrase2\" is translated differently in 1 places.\n";
     $this->setExpectedException('\\RuntimeException', $error);
     $allowDuplicates = false;
     $phraseFirstMock = $this->getMock('Magento\\Tools\\I18n\\Dictionary\\Phrase', [], [], '', false);
     $phraseFirstMock->expects($this->once())->method('getPhrase')->will($this->returnValue('phrase1'));
     $phraseSecondMock = $this->getMock('Magento\\Tools\\I18n\\Dictionary\\Phrase', [], [], '', false);
     $phraseSecondMock->expects($this->once())->method('getPhrase')->will($this->returnValue('phrase2'));
     $this->dictionaryLoaderMock->expects($this->any())->method('load')->will($this->returnValue($this->dictionaryMock));
     $phrases = [$this->getMock('Magento\\Tools\\I18n\\Dictionary\\Phrase', [], [], '', false)];
     $this->dictionaryMock->expects($this->once())->method('getPhrases')->will($this->returnValue([$phrases]));
     $this->dictionaryMock->expects($this->once())->method('getDuplicates')->will($this->returnValue([[$phraseFirstMock], [$phraseSecondMock]]));
     $this->_generator->generate('dictionary_path', 'pack_path', 'locale', 'mode', $allowDuplicates);
 }