Commit b7a77954 authored by webchick's avatar webchick

Issue #1750228 by Boobaa, corvus_ch: Fixed Adding a new language with empty...

Issue #1750228 by Boobaa, corvus_ch: Fixed Adding a new language with empty .po file and locale.module enabled throws a fatal error.
parent 79b9a36c
......@@ -230,6 +230,10 @@ public function getSeek() {
*/
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;
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Gettext\PoStreamReader;
use Drupal\Component\Gettext\PoMemoryWriter;
use Drupal\locale\PoDatabaseWriter;
use Exception;
/**
* Static class providing Drupal specific Gettext functionality.
......
......@@ -76,6 +76,13 @@ function testStandalonePoFile() {
$skip_message = format_plural(2, 'A translation string was skipped because of disallowed or malformed HTML. <a href="@url">See the log</a> for details.', '@count translation strings were skipped because of disallowed or malformed HTML. <a href="@url">See the log</a> for details.', array('@url' => url('admin/reports/dblog')));
$this->assertRaw($skip_message, t('Unsafe strings were skipped.'));
// Try importing a zero byte sized .po file.
$this->importPoFile($this->getEmptyPoFile(), array(
'langcode' => 'fr',
));
// The import should have created 0 string and rejected 0.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 0, '%update' => 0, '%delete' => 0)), 'The empty translation file was successfully imported.');
// Try importing a .po file which doesn't exist.
$name = $this->randomName(16);
......@@ -338,6 +345,13 @@ function getPoFile() {
EOF;
}
/**
* Helper function that returns a empty .po file.
*/
function getEmptyPoFile() {
return '';
}
/**
* Helper function that returns a bad .po file.
*/
......
......@@ -496,13 +496,17 @@ function locale_translate_batch_finished($success, $results) {
$additions = $updates = $deletes = $skips = 0;
drupal_set_message(format_plural(count($results['files']), 'One translation file imported.', '@count translation files imported.'));
$skipped_files = array();
foreach ($results['stats'] as $filepath => $report) {
$additions += $report['additions'];
$updates += $report['updates'];
$deletes += $report['deletes'];
$skips += $report['skips'];
if ($report['skips'] > 0) {
$skipped_files[] = $filepath;
// If there are no results and/or no stats (eg. coping with an empty .po
// file), simply do nothing.
if ($results && isset($results['stats'])) {
foreach ($results['stats'] as $filepath => $report) {
$additions += $report['additions'];
$updates += $report['updates'];
$deletes += $report['deletes'];
$skips += $report['skips'];
if ($report['skips'] > 0) {
$skipped_files[] = $filepath;
}
}
}
drupal_set_message(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => $additions, '%update' => $updates, '%delete' => $deletes)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment