Beispiel #1
0
 /**
  * Generate language pack
  *
  * @param string $dictionaryPath
  * @param string $locale
  * @param string $mode One of const of WriterInterface::MODE_
  * @param bool $allowDuplicates
  * @return void
  * @throws \RuntimeException
  */
 public function generate($dictionaryPath, $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->writeDictionary($dictionary, $locale, $mode);
 }
Beispiel #2
0
 public function testGenerate()
 {
     $dictionaryPath = 'dictionary_path';
     $localeString = 'locale';
     $mode = 'mode';
     $allowDuplicates = true;
     $localeMock = $this->getMock('Magento\\Setup\\Module\\I18n\\Locale', [], [], '', false);
     $phrases = [$this->getMock('Magento\\Setup\\Module\\I18n\\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('writeDictionary')->with($this->dictionaryMock, $localeMock, $mode);
     $this->_generator->generate($dictionaryPath, $localeString, $mode, $allowDuplicates);
 }