You are here

public function PoMemoryWriter::writeItem in Localization update 7.2

Implements PoWriterInterface::writeItem().

Overrides PoWriterInterface::writeItem

1 call to PoMemoryWriter::writeItem()
PoMemoryWriter::writeItems in includes/gettext/PoMemoryWriter.php
Implements PoWriterInterface::writeItems().

File

includes/gettext/PoMemoryWriter.php, line 30
Definition of Drupal\Component\Gettext\PoMemoryWriter.

Class

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

Code

public function writeItem(PoItem $item) {
  $context = $item
    ->getContext();
  $context = $context != NULL ? $context : '';
  if ($item
    ->isPlural()) {
    $sources = $item
      ->getSource();
    $translations = $item
      ->getTranslation();

    // Build additional source strings for plurals.
    $entries = array_keys($translations);
    for ($i = 3; $i <= count($entries); $i++) {
      $sources[] = $sources[1];
    }
    $translations = array_map('_locale_import_append_plural', $translations, $entries);
    $sources = array_map('_locale_import_append_plural', $sources, $entries);
    foreach ($entries as $index) {
      $this->_items[][$sources[$index]] = $translations[$index];
    }
  }
  else {
    $this->_items[$context][$item
      ->getSource()] = $item
      ->getTranslation();
  }
}