Index: includes/locale.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/locale.inc,v retrieving revision 1.254 diff -u -p -r1.254 locale.inc --- includes/locale.inc 1 May 2010 08:12:22 -0000 1.254 +++ includes/locale.inc 2 May 2010 06:20:03 -0000 @@ -685,30 +685,35 @@ function _locale_import_one_string($op, // Since we only need to parse the header if we ought to update the // plural formula, only run this if we don't need to keep existing // 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. - if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->uri)) { - list($nplurals, $plural) = $p; - db_update('languages') - ->fields(array( - 'plurals' => $nplurals, - 'formula' => $plural, - )) - ->condition('language', $lang) - ->execute(); + if ($header_done) { + watchdog('locale', 'An empty message ID string was found during .po import. The string was dropped.', array(), WATCHDOG_WARNING); } else { - db_update('languages') - ->fields(array( - 'plurals' => 0, - 'formula' => '', - )) - ->condition('language', $lang) - ->execute(); + $header = _locale_import_parse_header($value['msgstr']); + + // Get the plural formula and update in database. + if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->uri)) { + list($nplurals, $plural) = $p; + db_update('languages') + ->fields(array( + 'plurals' => $nplurals, + 'formula' => $plural, + )) + ->condition('language', $lang) + ->execute(); + } + else { + db_update('languages') + ->fields(array( + 'plurals' => 0, + 'formula' => '', + )) + ->condition('language', $lang) + ->execute(); + } + $header_done = TRUE; } } - $header_done = TRUE; } else { @@ -1234,9 +1239,9 @@ function _locale_parse_js_file($filepath */ /** - * Generates a structured array of all strings with translations in - * $language, if given. This array can be used to generate an export - * of the string in the database. + * Generates a structured array of all non-empty source strings with + * translations in $language, if given. This array can be used to generate an + * export of the string in the database. * * @param $language * Language object to generate the output for, or NULL if generating @@ -1246,10 +1251,10 @@ function _locale_parse_js_file($filepath */ function _locale_export_get_strings($language = NULL, $group = 'default') { if (isset($language)) { - $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.translation, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = :textgroup ORDER BY t.plid, t.plural", array(':language' => $language->language, ':textgroup' => $group)); + $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.translation, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = :textgroup AND s.source != '' ORDER BY t.plid, t.plural", array(':language' => $language->language, ':textgroup' => $group)); } else { - $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE s.textgroup = :textgroup ORDER BY t.plid, t.plural", array(':textgroup' => $group)); + $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE s.textgroup = :textgroup AND s.source != '' ORDER BY t.plid, t.plural", array(':textgroup' => $group)); } $strings = array(); foreach ($result as $child) { Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.292 diff -u -p -r1.292 locale.module --- modules/locale/locale.module 29 Apr 2010 05:15:43 -0000 1.292 +++ modules/locale/locale.module 2 May 2010 06:20:12 -0000 @@ -634,6 +634,12 @@ function locale($string = NULL, $context $langcode = isset($langcode) ? $langcode : $language->language; + if ($string === '') { + // Avoid checking for empty strings and also creating empty strings in the + // translation database. + return ''; + } + // Store database cached translations in a static variable. Only build the // cache after $language has been set to avoid an unnecessary cache rebuild. if (!isset($locale_t[$langcode]) && isset($language)) {