Index: l10n_community.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/l10n_community.module,v retrieving revision 1.1.2.15 diff -u -p -r1.1.2.15 l10n_community.module --- l10n_community.module 2 Jan 2008 23:14:12 -0000 1.1.2.15 +++ l10n_community.module 7 Mar 2008 18:24:05 -0000 @@ -660,11 +660,13 @@ function l10n_community_get_errors($uri) * is added. This is an edge case, but possibly not desired. */ function l10n_community_target_save($sid, $translation, $langcode, $uid, $suggestion, &$inserted, &$updated, &$unchanged, &$suggested) { - - // Look for an existing active translation. - $existing_string = db_fetch_object(db_query("SELECT sid, tid, translation FROM {l10n_community_translation} WHERE sid = %d AND language = '%s' AND is_suggestion = 0 AND is_active = 1", $sid, $langcode)); - - if (isset($existing_string->sid)) { + + // Look for an existing active translation and grab source string. + $existing_string = db_fetch_object(db_query("SELECT s.value, t.sid, t.tid, t.translation FROM {l10n_community_string} s LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid WHERE s.sid = %d AND ((t.sid IS NULL) OR (t.language = '%s' AND t.is_suggestion = 0 AND t.is_active = 1))", $sid, $langcode)); + $translation = l10n_community_trim($translation, $existing_string->value); + + if (!empty($existing_string->sid)) { + // We have an active translation. if ($existing_string->translation != $translation) { // And what we should save now is different. @@ -703,6 +705,23 @@ function l10n_community_target_save($sid } /** + * Special trimming, make spacing and new lines the same in translation as in the source + * + * @param $translation + * Translation string + * @param $source + * Source string + * @return + * Translation string with the right beginning and ending chars + */ +function l10n_community_trim($translation, $source) { + $matches = array(); + $chars = '\n\s\r\t'; + preg_match("/^([$chars]*).*[^$chars]([$chars]*)\$/", $source, $matches); + return $matches[1].trim($translation).$matches[2]; +} + +/** * Set a message based on the number of translations changed. * * Used by both the save and import process. Index: l10n_community.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/l10n_community.install,v retrieving revision 1.1.2.10 diff -u -p -r1.1.2.10 l10n_community.install --- l10n_community.install 17 Jan 2008 01:24:37 -0000 1.1.2.10 +++ l10n_community.install 7 Mar 2008 18:24:07 -0000 @@ -170,6 +170,28 @@ function l10n_community_update_5002() { } /** + * Clean up starting and trailing spaces and new lines in translations + */ +function l10n_community_update_5003() { + $ret = array(); + // We just search for strings that begin or end with these characters + foreach (array('\n', ' ') as $char) { + $result = db_query("SELECT s.sid, s.value, t.tid, t.translation FROM {l10n_community_string} s INNER JOIN {l10n_community_translation} t ON s.sid = t.sid WHERE s.value LIKE '%s%%' OR s.value LIKE '%%%s' OR t.translation LIKE '%s%%' OR t.translation LIKE '%%%s'", $char, $char, $char, $char); + while ($string = db_fetch_object($result)) { + if ($string->translation) { + $trimmed = l10n_community_trim($string->translation, $string->value); + if ($trimmed != $string->translation) { + db_query("UPDATE {l10n_community_translation} SET translation = '%s' WHERE tid = %d", $trimmed, $string->tid); + drupal_set_message("Fixed string $string->sid: ". check_plain(substr($string->translation, 0, 50))); + } + } + } + } + + return $ret; +} + +/** * Implementation of hook_uninstall(). */ function l10n_community_uninstall() {