示例#1
0
 /**
  * {@inheritdoc}
  */
 public function write(Phrase $phrase)
 {
     $fields = [$phrase->getCompiledPhrase(), $phrase->getCompiledTranslation()];
     if (($contextType = $phrase->getContextType()) && ($contextValue = $phrase->getContextValueAsString())) {
         $fields[] = $contextType;
         $fields[] = $contextValue;
     }
     fputcsv($this->_fileHandler, $fields, ',', '"');
 }
示例#2
0
 public function testWriteWithoutContext()
 {
     $this->_phraseFirstMock->expects($this->once())->method('getCompiledPhrase')->willReturn('phrase1');
     $this->_phraseFirstMock->expects($this->once())->method('getCompiledTranslation')->willReturn('translation1');
     $this->_phraseFirstMock->expects($this->once())->method('getContextType')->will($this->returnValue(''));
     $this->_phraseSecondMock->expects($this->once())->method('getCompiledPhrase')->willReturn('phrase2');
     $this->_phraseSecondMock->expects($this->once())->method('getCompiledTranslation')->willReturn('translation2');
     $this->_phraseSecondMock->expects($this->once())->method('getContextType')->willReturn('context_type2');
     $this->_phraseSecondMock->expects($this->once())->method('getContextValueAsString')->willReturn('');
     $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     /** @var \Magento\Setup\Module\I18n\Dictionary\Writer\Csv $writer */
     $writer = $objectManagerHelper->getObject('Magento\\Setup\\Module\\I18n\\Dictionary\\Writer\\Csv', ['outputFilename' => $this->_testFile]);
     $writer->write($this->_phraseFirstMock);
     $writer->write($this->_phraseSecondMock);
     $expected = "phrase1,translation1\nphrase2,translation2\n";
     $this->assertEquals($expected, file_get_contents($this->_testFile));
 }
示例#3
0
文件: Csv.php 项目: nja78/magento2
    /**
     * {@inheritdoc}
     */
    public function write(Phrase $phrase)
    {
        $fields = [$phrase->getPhrase(), $phrase->getTranslation()];
        $encloseQuote = $phrase->getQuote() == Phrase::QUOTE_DOUBLE ? Phrase::QUOTE_DOUBLE : Phrase::QUOTE_SINGLE;
        $fields[0] = $this->compileString($fields[0], $encloseQuote);
        $fields[1] = $this->compileString($fields[1], $encloseQuote);
        if (($contextType = $phrase->getContextType()) && ($contextValue = $phrase->getContextValueAsString())) {
            $fields[] = $contextType;
            $fields[] = $contextValue;
        }

        fputcsv($this->_fileHandler, $fields, ',', '"');
    }
 /**
  * @param \Magento\Setup\Module\I18n\Dictionary\Phrase $phrase
  * @param array $context
  * @return string
  */
 protected function buildFilePath($phrase, $context)
 {
     $path = $this->getContext()->buildPathToLocaleDirectoryByContext($phrase->getContextType(), $context);
     return $path . Locale::DEFAULT_SYSTEM_LOCALE . '.' . Csv::FILE_EXTENSION;
 }
示例#5
0
 /**
  * Add phrase to pack container
  *
  * @param Phrase $phrase
  * @return void
  */
 public function addPhrase(Phrase $phrase)
 {
     $this->_phrases[] = $phrase;
     $this->_phrasesByKey[$phrase->getKey()][] = $phrase;
 }
 public function testGetKey()
 {
     $phrase = new Phrase('phrase', 'translation', 'context_type', 'context_value1');
     $this->assertEquals('phrase::context_type', $phrase->getKey());
 }
 /**
  * @param \Magento\Setup\Module\I18n\Dictionary\Phrase $phrase
  * @param array $context
  * @return string
  */
 protected function buildFilePath($phrase, $context)
 {
     $path = $this->getContext()->buildPathToLocaleDirectoryByContext($phrase->getContextType(), $context);
     return \Magento\Framework\App\Utility\Files::init()->getPathToSource() . '/' . $path . \Magento\Setup\Module\I18n\Locale::DEFAULT_SYSTEM_LOCALE . '.' . \Magento\Setup\Module\I18n\Pack\Writer\File\Csv::FILE_EXTENSION;
 }