Exemplo n.º 1
0
 /**
  * Generate dictionary
  *
  * @param string $directory
  * @param string $outputFilename
  * @param bool $withContext
  * @throws \UnexpectedValueException
  * @return void
  */
 public function generate($directory, $outputFilename, $withContext = false)
 {
     $optionResolver = $this->optionResolverFactory->create($directory, $withContext);
     $parser = $this->getActualParser($withContext);
     $parser->parse($optionResolver->getOptions());
     $phraseList = $parser->getPhrases();
     if (!count($phraseList)) {
         throw new \UnexpectedValueException('No phrases found in the specified dictionary file.');
     }
     foreach ($phraseList as $phrase) {
         $this->getDictionaryWriter($outputFilename)->write($phrase);
     }
     $this->writer = null;
 }
 /**
  * @return array
  * @throws \RuntimeException
  */
 public function defaultLocaleDataProvider()
 {
     $parser = $this->prepareParser();
     $optionResolverFactory = new ResolverFactory();
     $optionResolver = $optionResolverFactory->create(BP, true);
     $parser->parse($optionResolver->getOptions());
     $defaultLocale = [];
     foreach ($parser->getPhrases() as $key => $phrase) {
         if (!$phrase->getContextType() || !$phrase->getContextValue()) {
             throw new \RuntimeException(sprintf('Missed context in row #%d.', $key + 1));
         }
         foreach ($phrase->getContextValue() as $context) {
             $phraseText = $this->eliminateSpecialChars($phrase->getPhrase());
             $phraseTranslation = $this->eliminateSpecialChars($phrase->getTranslation());
             $file = $this->buildFilePath($phrase, $context);
             $defaultLocale[$file]['file'] = $file;
             $defaultLocale[$file]['phrases'][$phraseText] = $phraseTranslation;
         }
     }
     return $defaultLocale;
 }
Exemplo n.º 3
0
 /**
  * @expectedException \UnexpectedValueException
  * @expectedExceptionMessage No phrases found in the specified dictionary file.
  */
 public function testGenerateWithNoPhrases()
 {
     $baseDir = 'no_phrases';
     $outputFilename = 'no_file.csv';
     $filesOptions = ['file1', 'file2'];
     $optionResolver = $this->getMock('Magento\\Setup\\Module\\I18n\\Dictionary\\Options\\Resolver', [], [], '', false);
     $optionResolver->expects($this->once())->method('getOptions')->will($this->returnValue($filesOptions));
     $this->optionsResolverFactory->expects($this->once())->method('create')->with($this->equalTo($baseDir), $this->equalTo(true))->will($this->returnValue($optionResolver));
     $this->contextualParserMock->expects($this->once())->method('parse')->with($filesOptions);
     $this->contextualParserMock->expects($this->once())->method('getPhrases')->will($this->returnValue([]));
     $this->generator->generate($baseDir, $outputFilename, true);
 }