diff options
-rw-r--r-- | includes/locale.inc | 4 | ||||
-rw-r--r-- | modules/locale/locale.test | 95 |
2 files changed, 87 insertions, 12 deletions
diff --git a/includes/locale.inc b/includes/locale.inc index a1cbed4d5..76861bae7 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -650,8 +650,8 @@ function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = } } - // End of PO file, flush last entry - if (!empty($current) && !empty($current['msgstr'])) { + // End of PO file, flush last entry. + if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { _locale_import_one_string($op, $current, $mode, $lang, $file, $group); } elseif ($context != "COMMENT") { diff --git a/modules/locale/locale.test b/modules/locale/locale.test index 004b332a0..2efa63d82 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -582,7 +582,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'Translation import', - 'description' => 'Tests the importation of locale files.', + 'description' => 'Tests the import of locale files.', 'group' => 'Locale', ); } @@ -600,7 +600,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { } /** - * Test importation of standalone .po files. + * Test import of standalone .po files. */ function testStandalonePoFile() { // Try importing a .po file. @@ -698,8 +698,8 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { } /** - * Test automatic importation of a module's translation files when a language - * is enabled. + * Test automatic import of a module's translation files when a language is + * enabled. */ function testAutomaticModuleTranslationImportLanguageEnable() { // Code for the language - manually set to match the test translation file. @@ -737,8 +737,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { } /** - * Test automatic importation of a module's translation files when a language - * is enabled. + * Test msgctxt context support. */ function testLanguageContext() { // Try importing a .po file. @@ -751,6 +750,43 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { } /** + * Test empty msgstr at end of .po file see #611786. + */ + function testEmptyMsgstr() { + $langcode = 'hu'; + + // Try importing a .po file. + $this->importPoFile($this->getPoFileWithMsgstr(), array( + 'langcode' => $langcode, + )); + + $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' => 1, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.')); + $this->assertIdentical(t('Operations', array(), array('langcode' => $langcode)), 'Műveletek', t('String imported and translated.')); + + // Try importing a .po file. + $this->importPoFile($this->getPoFileWithEmptyMsgstr(), array( + 'langcode' => $langcode, + 'mode' => 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' => 1)), t('The translation file was successfully imported.')); + // This is the language indicator on the translation search screen for + // untranslated strings. Copied straight from locale.inc. + $language_indicator = "<em class=\"locale-untranslated\">$langcode</em> "; + $str = "Operations"; + $search = array( + 'string' => $str, + 'language' => 'all', + 'translation' => 'all', + 'group' => 'all', + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); + // assertText() seems to remove the input field where $str always could be + // found, so this is not a false assert. + $this->assertText($str, t('Search found the string.')); + $this->assertRaw($language_indicator, t('String is untranslated again.')); + } + + /** * Helper function: import a standalone .po file in a given language. * * @param $contents @@ -773,7 +809,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { return <<< EOF msgid "" msgstr "" -"Project-Id-Version: Drupal 6\\n" +"Project-Id-Version: Drupal 7\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n" @@ -809,7 +845,7 @@ EOF; return <<< EOF msgid "" msgstr "" -"Project-Id-Version: Drupal 6\\n" +"Project-Id-Version: Drupal 7\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n" @@ -835,7 +871,7 @@ EOF; return <<< EOF msgid "" msgstr "" -"Project-Id-Version: Drupal 6\\n" +"Project-Id-Version: Drupal 7\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n" @@ -858,7 +894,7 @@ EOF; return <<< EOF msgid "" msgstr "" -"Project-Id-Version: Drupal 6\\n" +"Project-Id-Version: Drupal 7\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n" @@ -873,6 +909,45 @@ msgstr "Svi." EOF; } + /** + * Helper function that returns a .po file with an empty last item. + */ + function getPoFileWithEmptyMsgstr() { + 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: nplurals=2; plural=(n > 1);\\n" + +msgid "Operations" +msgstr "" + +EOF; + } + /** + * Helper function that returns a .po file with an empty last item. + */ + function getPoFileWithMsgstr() { + 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: nplurals=2; plural=(n > 1);\\n" + +msgid "Operations" +msgstr "Műveletek" + +msgid "Will not appear in Drupal core, so we can ensure the test passes" +msgstr "" + +EOF; + } } |