Index: includes/locale.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/locale.inc,v retrieving revision 1.258 diff -u -p -r1.258 locale.inc --- includes/locale.inc 30 Jul 2010 02:47:27 -0000 1.258 +++ includes/locale.inc 11 Aug 2010 15:33:13 -0000 @@ -488,7 +488,8 @@ function _locale_import_read_po($op, $fi $lineno = 0; // Current line while (!feof($fd)) { - $line = fgets($fd, 10*1024); // A line should not be this long + // A line should not be this long. + $line = fgets($fd, 10*1024); if ($lineno == 0) { // The first line might come with a UTF-8 BOM, which should be removed. $line = str_replace("\xEF\xBB\xBF", '', $line); @@ -496,23 +497,28 @@ function _locale_import_read_po($op, $fi $lineno++; $line = trim(strtr($line, array("\\\n" => ""))); - if (!strncmp("#", $line, 1)) { // A comment - if ($context == "COMMENT") { // Already in comment context: add + if (!strncmp("#", $line, 1)) { + // A comment. + if ($context == "COMMENT") { + // Already in comment context: add. $current["#"][] = substr($line, 1); } - elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one + elseif ($context == "MSGSTR" || $context == "MSGSTR_ARR") { + // End current entry, start a new one. _locale_import_one_string($op, $current, $mode, $lang, $file, $group); $current = array(); $current["#"][] = substr($line, 1); $context = "COMMENT"; } - else { // Parse error + else { + // Parse error. _locale_import_message('The translation file %filename contains an error: "msgstr" was expected but not found on line %line.', $file, $lineno); return FALSE; } } elseif (!strncmp("msgid_plural", $line, 12)) { - if ($context != "MSGID") { // Must be plural form for current entry + // Must be plural form for current entry. + if ($context != "MSGID") { _locale_import_message('The translation file %filename contains an error: "msgid_plural" was expected but not found on line %line.', $file, $lineno); return FALSE; } @@ -526,11 +532,13 @@ function _locale_import_read_po($op, $fi $context = "MSGID_PLURAL"; } elseif (!strncmp("msgid", $line, 5)) { - if ($context == "MSGSTR") { // End current entry, start a new one + if ($context == "MSGSTR" || $context == "MSGSTR_ARR") { + // End current entry, start a new one. _locale_import_one_string($op, $current, $mode, $lang, $file, $group); $current = array(); } - elseif ($context == "MSGID") { // Already in this context? Parse error + elseif ($context == "MSGID") { + // Already in this context? Parse error. _locale_import_message('The translation file %filename contains an error: "msgid" is unexpected on line %line.', $file, $lineno); return FALSE; } @@ -544,11 +552,13 @@ function _locale_import_read_po($op, $fi $context = "MSGID"; } elseif (!strncmp("msgctxt", $line, 7)) { - if ($context == "MSGSTR") { // End current entry, start a new one + if ($context == "MSGSTR" || $context == "MSGSTR_ARR") { + // End current entry, start a new one _locale_import_one_string($op, $current, $mode, $lang, $file, $group); $current = array(); } - elseif (!empty($current["msgctxt"])) { // Already in this context? Parse error + elseif (!empty($current["msgctxt"])) { + // Already in this context? Parse error. _locale_import_message('The translation file %filename contains an error: "msgctxt" is unexpected on line %line.', $file, $lineno); return FALSE; } @@ -562,7 +572,8 @@ function _locale_import_read_po($op, $fi $context = "MSGCTXT"; } elseif (!strncmp("msgstr[", $line, 7)) { - if (($context != "MSGID") && ($context != "MSGCTXT") && ($context != "MSGID_PLURAL") && ($context != "MSGSTR_ARR")) { // Must come after msgid, msgxtxt, msgid_plural, or msgstr[] + if ($context != "MSGID" && $context != "MSGCTXT" && $context != "MSGID_PLURAL" && $context != "MSGSTR_ARR") { + // Must come after msgid, msgxtxt, msgid_plural, or msgstr[]. _locale_import_message('The translation file %filename contains an error: "msgstr[]" is unexpected on line %line.', $file, $lineno); return FALSE; } @@ -582,7 +593,8 @@ function _locale_import_read_po($op, $fi $context = "MSGSTR_ARR"; } elseif (!strncmp("msgstr", $line, 6)) { - if (($context != "MSGID") && ($context != "MSGCTXT")) { // Should come just after a msgid or msgctxt block + if ($context != "MSGID" && $context != "MSGCTXT") { + // Should come just after a msgid or msgctxt block. _locale_import_message('The translation file %filename contains an error: "msgstr" is unexpected on line %line.', $file, $lineno); return FALSE; } @@ -620,7 +632,7 @@ function _locale_import_read_po($op, $fi } } - // End of PO file, flush last entry + // End of PO file, flush last entry. if (!empty($current) && !empty($current['msgstr'])) { _locale_import_one_string($op, $current, $mode, $lang, $file, $group); } Index: modules/locale/locale.test =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.test,v retrieving revision 1.76 diff -u -p -r1.76 locale.test --- modules/locale/locale.test 5 Aug 2010 23:53:38 -0000 1.76 +++ modules/locale/locale.test 11 Aug 2010 15:33:13 -0000 @@ -611,7 +611,7 @@ class LocaleImportFunctionalTest extends $this->assertRaw(t('The language %language has been created.', array('%language' => 'French')), t('The language has been automatically created.')); // The import should have created 7 strings. - $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' => 7, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.')); + $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' => 9, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.')); // This import should have saved plural forms to have 2 variants. $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, t('Plural number initialized.')); @@ -778,6 +778,11 @@ msgstr "" "Content-Transfer-Encoding: 8bit\\n" "Plural-Forms: nplurals=2; plural=(n > 1);\\n" +msgid "One sheep" +msgid_plural "@count sheep" +msgstr[0] "un mouton" +msgstr[1] "@count moutons" + msgid "Monday" msgstr "lundi" @@ -1989,4 +1994,3 @@ class LocaleDateFormatsFunctionalTest ex $this->assertText($french_date, t('French date format appears')); } } -