예제 #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);
 }
예제 #2
0
 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\\Code\\Dictionary\\Phrase', array(), array(), '', false);
     $phraseFirstMock->expects($this->once())->method('getPhrase')->will($this->returnValue('phrase1'));
     $phraseSecondMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', array(), array(), '', 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\\Code\\Dictionary\\Phrase', [], [], '', false)];
     $this->dictionaryMock->expects($this->once())->method('getPhrases')->will($this->returnValue([$phrases]));
     $this->dictionaryMock->expects($this->once())->method('getDuplicates')->will($this->returnValue(array(array($phraseFirstMock), array($phraseSecondMock))));
     $this->_generator->generate('dictionary_path', 'pack_path', 'locale', 'mode', $allowDuplicates);
 }