diff -u b/core/includes/gettext.inc b/core/includes/gettext.inc --- b/core/includes/gettext.inc +++ b/core/includes/gettext.inc @@ -408,7 +408,7 @@ // If 'msgid' is empty, it means we got values for the header of the // file as per the structure of the Gettext format. $locale_plurals = variable_get('locale_translation_plurals', array()); - if (count(array_filter($overwrite_options)) || empty($locale_plurals[$lang]['plurals'])) { + if (array_sum($overwrite_options) || empty($locale_plurals[$lang]['plurals'])) { // 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. @@ -488,33 +488,34 @@ ); // Look up the source string and any existing translation. - $existing_translation = NULL; - $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context", array(':source' => $source, ':context' => $context))->fetchField(); - if ($lid) { - $existing_translation = db_query("SELECT * FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $langcode))->fetchObject(); - } + $string = db_query("SELECT s.lid, t.customized FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context", array( + ':source' => $source, + ':context' => $context, + ':language' => $langcode, + )) + ->fetchObject(); if (!empty($translation)) { // Skip this string unless it passes a check for dangerous code. if (!locale_string_is_safe($translation)) { watchdog('locale', 'Import of string "%string" was skipped because of disallowed or malformed HTML.', array('%string' => $translation), WATCHDOG_ERROR); $report['skips']++; - $lid = 0; + return 0; } - elseif ($lid) { + elseif (isset($string->lid)) { // We have this source string saved already. db_update('locales_source') ->fields(array( 'location' => $location, )) - ->condition('lid', $lid) + ->condition('lid', $string->lid) ->execute(); - if (empty($existing_translation)) { + if (!isset($string->customized)) { // No translation in this language. db_insert('locales_target') ->fields(array( - 'lid' => $lid, + 'lid' => $string->lid, 'language' => $langcode, 'translation' => $translation, 'customized' => $customized, @@ -523,7 +524,7 @@ $report['additions']++; } - elseif ($overwrite_options[$existing_translation->customized ? 'customized' : 'not_customized']) { + elseif ($overwrite_options[$string->customized ? 'customized' : 'not_customized']) { // Translation exists, only overwrite if instructed. db_update('locales_target') ->fields(array( @@ -531,11 +532,12 @@ 'customized' => $customized, )) ->condition('language', $langcode) - ->condition('lid', $lid) + ->condition('lid', $string->lid) ->execute(); $report['updates']++; } + return $string->lid; } else { // No such source string in the database yet. @@ -557,19 +559,19 @@ ->execute(); $report['additions']++; + return $lid; } } - elseif (!empty($existing_translation) && $overwrite_options[$existing_translation->customized ? 'customized' : 'not_customized']) { + elseif (isset($string->lid) && isset($string->customized) && $overwrite_options[$string->customized ? 'customized' : 'not_customized']) { // Empty translation, remove existing if instructed. db_delete('locales_target') ->condition('language', $langcode) - ->condition('lid', $lid) + ->condition('lid', $string->lid) ->execute(); $report['deletes']++; + return $string->lid; } - - return $lid; } /** diff -u b/core/modules/locale/locale.test b/core/modules/locale/locale.test --- b/core/modules/locale/locale.test +++ b/core/modules/locale/locale.test @@ -1485,7 +1485,7 @@ return <<< EOF msgid "" msgstr "" -"Project-Id-Version: Drupal 6\\n" +"Project-Id-Version: Drupal 8\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n" @@ -1504,7 +1504,7 @@ return <<< EOF msgid "" msgstr "" -"Project-Id-Version: Drupal 6\\n" +"Project-Id-Version: Drupal 8\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n"