/** * 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; }