Example #1
0
 public function testPhraseCollecting()
 {
     $phraseFirstMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', array(), array(), '', false);
     $phraseSecondMock = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Phrase', array(), array(), '', false);
     $this->_dictionary->addPhrase($phraseFirstMock);
     $this->_dictionary->addPhrase($phraseSecondMock);
     $this->assertEquals(array($phraseFirstMock, $phraseSecondMock), $this->_dictionary->getPhrases());
 }
Example #2
0
 /**
  * Build pack files data
  *
  * @param Dictionary $dictionary
  * @return array
  * @throws \RuntimeException
  */
 protected function _buildPackFilesData(Dictionary $dictionary)
 {
     $files = array();
     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 3 columns: original phrase, translation, context');
         }
         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;
 }