예제 #1
0
 public function testGenerate()
 {
     $dictionaryPath = 'dictionary_path';
     $packPath = 'pack_path';
     $localeString = 'locale';
     $mode = 'mode';
     $allowDuplicates = true;
     $localeMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Locale', array(), array(), '', false);
     $phrases = [$this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', [], [], '', false)];
     $this->dictionaryMock->expects($this->once())->method('getPhrases')->will($this->returnValue([$phrases]));
     $this->factoryMock->expects($this->once())->method('createLocale')->with($localeString)->will($this->returnValue($localeMock));
     $this->dictionaryLoaderMock->expects($this->once())->method('load')->with($dictionaryPath)->will($this->returnValue($this->dictionaryMock));
     $this->packWriterMock->expects($this->once())->method('write')->with($this->dictionaryMock, $packPath, $localeMock, $mode);
     $this->_generator->generate($dictionaryPath, $packPath, $localeString, $mode, $allowDuplicates);
 }
예제 #2
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);
 }