writeItems example

'overwrite_options' => $options['overwrite_options'],
      'customized' => $options['customized'],
    ];
    $writer->setOptions($writer_options);
    $writer->setHeader($header);

    // Attempt to pipe all items from the file to the database.     try {
      if ($options['seek']) {
        $reader->setSeek($options['seek']);
      }
      $writer->writeItems($reader$options['items']);
    }
    catch (\Exception $exception) {
      throw $exception;
    }

    // Report back with an array of status information.     $report = $writer->getReport();

    // Add the seek position to the report. This is useful for the batch     // operation.     $report['seek'] = $reader->getSeek();
    
$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();
      $writer->writeItem($item);
      $writer->writeItems($reader);
      $writer->close();

      $response = new BinaryFileResponse($uri);
      $response->setContentDisposition('attachment', $filename);
      $form_state->setResponse($response);
    }
    else {
      $this->messenger()->addStatus($this->t('Nothing to export.'));
    }
  }

}

  public static function filesToArray($langcode, array $files) {
    $writer = new PoMemoryWriter();
    $writer->setLangcode($langcode);
    foreach ($files as $file) {
      $reader = new PoStreamReader();
      $reader->setURI($file->uri);
      $reader->setLangcode($langcode);
      $reader->open();
      $writer->writeItems($reader, -1);
    }
    return $writer->getData();
  }

}
Home | Imprint | This part of the site doesn't use cookies.