diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2012-03-13 12:44:26 -0700 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2012-03-13 12:45:49 -0700 |
commit | 8f096c6b62b11f04a847363f5fe173c021fae9be (patch) | |
tree | 75cca0aba0de10381ede800b46d37a2e2728b439 | |
parent | c6734081a8a08b01f5913a16a7e5d680906950c0 (diff) | |
download | brdo-8f096c6b62b11f04a847363f5fe173c021fae9be.tar.gz brdo-8f096c6b62b11f04a847363f5fe173c021fae9be.tar.bz2 |
Issue #655048 by Gábor Hojtsy, gumanist, intuited: Fixed Plural formula information blanked when importing a poorly-formed .po file.
-rw-r--r-- | includes/locale.inc | 11 | ||||
-rw-r--r-- | modules/locale/locale.test | 55 |
2 files changed, 56 insertions, 10 deletions
diff --git a/includes/locale.inc b/includes/locale.inc index 0db4d4a07..72e466802 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -978,7 +978,7 @@ 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, $plural) = $p; db_update('languages') @@ -989,15 +989,6 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL ->condition('language', $lang) ->execute(); } - else { - db_update('languages') - ->fields(array( - 'plurals' => 0, - 'formula' => '', - )) - ->condition('language', $lang) - ->execute(); - } } $header_done = TRUE; } diff --git a/modules/locale/locale.test b/modules/locale/locale.test index db0bead1e..c922c1df6 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -793,6 +793,25 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { // This import should not have changed number of plural forms. $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, t('Plural numbers untouched.')); + $this->importPoFile($this->getPoFileWithBrokenPlural(), array( + 'langcode' => 'fr', + 'mode' => 1, // Existing strings are kept, only new strings are added. + )); + + // Attempt to import broken .po file as well to prove that this + // will not overwrite the proper plural formula imported above. + $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, t('Broken plurals: plural numbers untouched.')); + + $this->importPoFile($this->getPoFileWithMissingPlural(), array( + 'langcode' => 'fr', + 'mode' => 1, // Existing strings are kept, only new strings are added. + )); + + // Attempt to import .po file which has no plurals and prove that this + // will not overwrite the proper plural formula imported above. + $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, t('No plurals: plural numbers untouched.')); + + // Try importing a .po file with overriding strings, and ensure existing // strings are overwritten. $this->importPoFile($this->getOverwritePoFile(), array( @@ -1072,6 +1091,42 @@ msgstr "" 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 "Ponedjeljak" +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 "lundi" +EOF; + } + } /** |