/** * Parse one type * * @param array $options * @return void */ protected function _parseByTypeOptions($options) { foreach ($this->_getFiles($options) as $file) { $adapter = $this->_adapters[$options['type']]; $adapter->parse($file); list($contextType, $contextValue) = $this->_context->getContextByPath($file); foreach ($adapter->getPhrases() as $phraseData) { $this->_addPhrase($phraseData, $contextType, $contextValue); } } }
/** * Build pack files data * * @param Dictionary $dictionary * @return array * @throws \RuntimeException */ protected function _buildPackFilesData(Dictionary $dictionary) { $files = []; foreach ($dictionary->getPhrases() as $key => $phrase) { if (!$phrase->getContextType() || !$phrase->getContextValue()) { throw new \RuntimeException(sprintf('Missed context in row #%d.', $key + 1) . "\n" . 'Each row has to consist of 4 columns: original phrase, translation, context type, context value'); } foreach ($phrase->getContextValue() as $context) { try { $path = $this->_context->buildPathToLocaleDirectoryByContext($phrase->getContextType(), $context); } catch (\InvalidArgumentException $e) { throw new \InvalidArgumentException($e->getMessage() . ' Row #' . ($key + 1) . '.'); } $filename = $this->_packPath . $path . $this->_locale . '.' . $this->_getFileExtension(); $files[$filename][$phrase->getPhrase()] = $phrase; } } return $files; }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Invalid context given: "invalid_type". */ public function testBuildPathToLocaleDirectoryByContextWithInvalidType() { $this->context->buildPathToLocaleDirectoryByContext('invalid_type', 'Magento_Module'); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Invalid context given: "invalid_type". */ public function testBuildPathToLocaleDirectoryByContextWithInvalidType() { $this->componentRegistrar->expects($this->any())->method('getPaths')->with(ComponentRegistrar::MODULE)->willReturn(['module' => '/path/to/module']); $this->context = new Context($this->componentRegistrar); $this->context->buildPathToLocaleDirectoryByContext('invalid_type', 'Magento_Module'); }