Commit 0c495e92 authored by webchick's avatar webchick
Browse files

Issue #655048 by Gábor Hojtsy, intuited: Fixed Plural formula information...

Issue #655048 by Gábor Hojtsy, intuited: Fixed Plural formula information blanked when importing a poorly-formed .po file.
parent ef5d9d89
......@@ -399,19 +399,15 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL
// data untouched or if we don't have an existing plural formula.
$header = _locale_import_parse_header($value['msgstr']);
// Get the plural formula and update in database.
// Get and store the plural formula if available.
if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->uri)) {
list($nplurals, $formula) = $p;
$locale_plurals[$lang] = array(
'plurals' => $nplurals,
'formula' => $formula,
);
variable_set('locale_translation_plurals', $locale_plurals);
}
else {
$nplurals = 0;
$formula = '';
}
$locale_plurals[$lang] = array(
'plurals' => $nplurals,
'formula' => $formula,
);
variable_set('locale_translation_plurals', $locale_plurals);
}
$header_done = TRUE;
}
......
......@@ -617,6 +617,15 @@ class LocalePluralFormatTest extends DrupalWebTestCase {
'langcode' => 'hr',
));
// Attempt to import some broken .po files as well to prove that these
// will not overwrite the proper plural formula imported above.
$this->importPoFile($this->getPoFileWithMissingPlural(), array(
'langcode' => 'fr',
));
$this->importPoFile($this->getPoFileWithBrokenPlural(), array(
'langcode' => 'hr',
));
// Reset static caches from locale_get_plural() to ensure we get fresh data.
drupal_static_reset('locale_get_plural');
drupal_static_reset('locale_get_plural:plurals');
......@@ -656,6 +665,7 @@ class LocalePluralFormatTest extends DrupalWebTestCase {
$name = tempnam('temporary://', "po_") . '.po';
file_put_contents($name, $contents);
$options['files[file]'] = $name;
$options['mode'] = LOCALE_IMPORT_OVERWRITE;
$this->drupalPost('admin/config/regional/translate/import', $options, t('Import'));
drupal_unlink($name);
}
......@@ -702,6 +712,41 @@ msgstr[0] "@count sat"
msgstr[1] "@count sata"
msgstr[2] "@count sati"
msgid "Monday"
msgstr "Ponedjeljak"
EOF;
}
/**
* Returns a .po file with a missing plural formula.
*/
function getPoFileWithMissingPlural() {
return <<< EOF
msgid ""
msgstr ""
"Project-Id-Version: Drupal 7\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
msgid "Monday"
msgstr "lundi"
EOF;
}
/**
* Returns a .po file with a broken plural formula.
*/
function getPoFileWithBrokenPlural() {
return <<< EOF
msgid ""
msgstr ""
"Project-Id-Version: Drupal 7\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: broken, will not parse\\n"
msgid "Monday"
msgstr "Ponedjeljak"
EOF;
......
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