class PoMemoryWriter

Same name in other branches
  1. 9 core/lib/Drupal/Component/Gettext/PoMemoryWriter.php \Drupal\Component\Gettext\PoMemoryWriter
  2. 8.9.x core/lib/Drupal/Component/Gettext/PoMemoryWriter.php \Drupal\Component\Gettext\PoMemoryWriter
  3. 10 core/lib/Drupal/Component/Gettext/PoMemoryWriter.php \Drupal\Component\Gettext\PoMemoryWriter

Defines a Gettext PO memory writer, to be used by the installer.

Hierarchy

Expanded class hierarchy of PoMemoryWriter

1 file declares its use of PoMemoryWriter
FileTranslation.php in core/lib/Drupal/Core/StringTranslation/Translator/FileTranslation.php

File

core/lib/Drupal/Component/Gettext/PoMemoryWriter.php, line 8

Namespace

Drupal\Component\Gettext
View source
class PoMemoryWriter implements PoWriterInterface {
    
    /**
     * Array to hold all PoItem elements.
     *
     * @var array
     */
    protected $items;
    
    /**
     * Constructor, initialize empty items.
     */
    public function __construct() {
        $this->items = [];
    }
    
    /**
     * {@inheritdoc}
     */
    public function writeItem(PoItem $item) {
        if (is_array($item->getSource())) {
            $item->setSource(implode(PoItem::DELIMITER, $item->getSource()));
            $item->setTranslation(implode(PoItem::DELIMITER, $item->getTranslation()));
        }
        $context = $item->getContext();
        $this->items[$context != NULL ? $context : ''][$item->getSource()] = $item->getTranslation();
    }
    
    /**
     * {@inheritdoc}
     */
    public function writeItems(PoReaderInterface $reader, $count = -1) {
        $forever = $count == -1;
        while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
            $this->writeItem($item);
        }
    }
    
    /**
     * Get all stored PoItem's.
     *
     * @return array PoItem
     */
    public function getData() {
        return $this->items;
    }
    
    /**
     * Implements Drupal\Component\Gettext\PoMetadataInterface:setLangcode().
     *
     * Not implemented. Not relevant for the MemoryWriter.
     */
    public function setLangcode($langcode) {
    }
    
    /**
     * Implements Drupal\Component\Gettext\PoMetadataInterface:getLangcode().
     *
     * Not implemented. Not relevant for the MemoryWriter.
     */
    public function getLangcode() {
    }
    
    /**
     * Implements Drupal\Component\Gettext\PoMetadataInterface:getHeader().
     *
     * Not implemented. Not relevant for the MemoryWriter.
     */
    public function getHeader() {
    }
    
    /**
     * Implements Drupal\Component\Gettext\PoMetadataInterface:setHeader().
     *
     * Not implemented. Not relevant for the MemoryWriter.
     */
    public function setHeader(PoHeader $header) {
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
PoMemoryWriter::$items protected property Array to hold all PoItem elements.
PoMemoryWriter::getData public function Get all stored PoItem's.
PoMemoryWriter::getHeader public function Implements Drupal\Component\Gettext\PoMetadataInterface:getHeader(). Overrides PoMetadataInterface::getHeader
PoMemoryWriter::getLangcode public function Implements Drupal\Component\Gettext\PoMetadataInterface:getLangcode(). Overrides PoMetadataInterface::getLangcode
PoMemoryWriter::setHeader public function Implements Drupal\Component\Gettext\PoMetadataInterface:setHeader(). Overrides PoMetadataInterface::setHeader
PoMemoryWriter::setLangcode public function Implements Drupal\Component\Gettext\PoMetadataInterface:setLangcode(). Overrides PoMetadataInterface::setLangcode
PoMemoryWriter::writeItem public function Writes the given item. Overrides PoWriterInterface::writeItem
PoMemoryWriter::writeItems public function Writes all or the given amount of items. Overrides PoWriterInterface::writeItems
PoMemoryWriter::__construct public function Constructor, initialize empty items.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.