Reads the given PO files into the database.
stdClass $file: File object with an URI property pointing at the file's path.
array $options: An array with options that can have the following elements:
array Report array as defined in Drupal\locale\PoDatabaseWriter.
Drupal\locale\PoDatabaseWriter
static function fileToDatabase($file, $options) {
// Add the default values to the options array.
$options += array(
'overwrite_options' => array(),
'customized' => LOCALE_NOT_CUSTOMIZED,
'items' => -1,
'seek' => 0,
);
// Instantiate and initialize the stream reader for this file.
$reader = new PoStreamReader();
$reader
->setLangcode($options['langcode']);
$reader
->setURI($file->uri);
try {
$reader
->open();
} catch (Exception $exception) {
throw $exception;
}
$header = $reader
->getHeader();
if (!$header) {
throw new Exception('Missing or malformed header.');
}
// Initialize the database writer.
$writer = new PoDatabaseWriter();
$writer
->setLangcode($options['langcode']);
$writer_options = array(
'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();
return $report;
}