You are here

class PoMemoryWriter in Service Container 7.2

Same name and namespace in other branches
  1. 7 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

File

lib/Drupal/Component/Gettext/PoMemoryWriter.php, line 13
Contains \Drupal\Component\Gettext\PoMemoryWriter.

Namespace

Drupal\Component\Gettext
View source
class PoMemoryWriter implements PoWriterInterface {

  /**
   * Array to hold all PoItem elements.
   *
   * @var array
   */
  private $_items;

  /**
   * Constructor, initialize empty items.
   */
  function __construct() {
    $this->_items = array();
  }

  /**
   * {@inheritdoc}
   */
  public function writeItem(PoItem $item) {
    if (is_array($item
      ->getSource())) {
      $item
        ->setSource(implode(LOCALE_PLURAL_DELIMITER, $item
        ->getSource()));
      $item
        ->setTranslation(implode(LOCALE_PLURAL_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.
   */
  function setLangcode($langcode) {
  }

  /**
   * Implements Drupal\Component\Gettext\PoMetadataInterface:getLangcode().
   *
   * Not implemented. Not relevant for the MemoryWriter.
   */
  function getLangcode() {
  }

  /**
   * Implements Drupal\Component\Gettext\PoMetadataInterface:getHeader().
   *
   * Not implemented. Not relevant for the MemoryWriter.
   */
  function getHeader() {
  }

  /**
   * Implements Drupal\Component\Gettext\PoMetadataInterface:setHeader().
   *
   * Not implemented. Not relevant for the MemoryWriter.
   */
  function setHeader(PoHeader $header) {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PoMemoryWriter::$_items private property Array to hold all PoItem elements.
PoMemoryWriter::getData public function Get all stored PoItem's.
PoMemoryWriter::getHeader function Implements Drupal\Component\Gettext\PoMetadataInterface:getHeader(). Overrides PoMetadataInterface::getHeader
PoMemoryWriter::getLangcode function Implements Drupal\Component\Gettext\PoMetadataInterface:getLangcode(). Overrides PoMetadataInterface::getLangcode
PoMemoryWriter::setHeader function Implements Drupal\Component\Gettext\PoMetadataInterface:setHeader(). Overrides PoMetadataInterface::setHeader
PoMemoryWriter::setLangcode 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 function Constructor, initialize empty items.