readItem example


  public function writeItem(PoItem $item) {
    $this->write($item);
  }

  /** * {@inheritdoc} */
  public function writeItems(PoReaderInterface $reader$count = -1) {
    $forever = $count == -1;
    while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
      $this->writeItem($item);
    }
  }

  /** * Implements Drupal\Component\Gettext\PoStreamInterface::getURI(). * * @throws \Exception * If the URI is not set. */
  public function getURI() {
    
$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;
  }
return ftell($this->fd);
  }

  /** * Read the header from the PO stream. * * The header is a special case PoItem, using the empty string as source and * key-value pairs as translation. We just reuse the item reader logic to * read the header. */
  private function readHeader() {
    $item = $this->readItem();
    // Handle the case properly when the .po file is empty (0 bytes).     if (!$item) {
      return;
    }
    $header = new PoHeader();
    $header->setFromString(trim($item->getTranslation()));
    $this->header = $header;
  }

  /** * Reads a line from the PO stream and stores data internally. * * Expands $this->current_item based on new data for the current item. If * this line ends the current item, it is saved with setItemFromArray() with * data from $this->current_item. * * An internal state machine is maintained in this reader using * $this->context as the reading state. PO items are in between COMMENT * states (when items have at least one line or comment in between them) or * indicated by MSGSTR or MSGSTR_ARR followed immediately by an MSGID or * MSGCTXT (when items closely follow each other). * * @return bool|null * FALSE if an error was logged, NULL otherwise. The errors are considered * non-blocking, so reading can continue, while the errors are collected * for later presentation. */
$item->setSource(implode(PoItem::DELIMITER, $item->getSource()));
      $item->setTranslation(implode(PoItem::DELIMITER, $item->getTranslation()));
    }
    $this->importString($item);
  }

  /** * {@inheritdoc} */
  public function writeItems(PoReaderInterface $reader$count = -1) {
    $forever = $count == -1;
    while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
      $this->writeItem($item);
    }
  }

  /** * Imports one string into the database. * * @param \Drupal\Component\Gettext\PoItem $item * The item being imported. * * @return int * The string ID of the existing string modified or the new string added. */
$reader->setLangcode($language->getId());
      $reader->setOptions($content_options);
      $languages = $this->languageManager->getLanguages();
      $language_name = isset($languages[$language->getId()]) ? $languages[$language->getId()]->getName() : '';
      $filename = $language->getId() . '.po';
    }
    else {
      // Template required.       $filename = 'drupal.pot';
    }

    $item = $reader->readItem();
    if (!empty($item)) {
      $uri = $this->fileSystem->tempnam('temporary://', 'po_');
      $header = $reader->getHeader();
      $header->setProjectName($this->config('system.site')->get('name'));
      $header->setLanguageName($language_name);

      $writer = new PoStreamWriter();
      $writer->setURI($uri);
      $writer->setHeader($header);

      $writer->open();
      
Home | Imprint | This part of the site doesn't use cookies.