Index: includes/locale.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/locale.inc,v retrieving revision 1.174.2.7 diff -u -r1.174.2.7 locale.inc --- includes/locale.inc 6 Jan 2009 15:36:51 -0000 1.174.2.7 +++ includes/locale.inc 2 Mar 2009 09:49:31 -0000 @@ -2162,6 +2162,7 @@ } // Construct the JavaScript file, if there are translations. + $data_hash = NULL; $data = $status = ''; if (!empty($translations)) { @@ -2178,24 +2179,27 @@ // Construct the filepath where JS translation files are stored. // There is (on purpose) no front end to edit that variable. $dir = file_create_path(variable_get('locale_js_directory', 'languages')); - + + // Has the hash code changed? + $changed_hash = $language->javascript != $data_hash; + // Delete old file, if we have no translations anymore, or a different file to be saved. - if (!empty($language->javascript) && (!$data || $language->javascript != $data_hash)) { + if (!empty($language->javascript) && (!$data || $changed_hash)) { file_delete(file_create_path($dir .'/'. $language->language .'_'. $language->javascript .'.js')); $language->javascript = ''; $status = 'deleted'; } - // Only create a new file if the content has changed. - if ($data && $language->javascript != $data_hash) { + // Only create a new file if the content has changed or the original file got lost. + $dest = $dir .'/'. $language->language .'_'. $data_hash .'.js'; + if ($data && ($changed_hash || !file_exists($dest))) { // Ensure that the directory exists and is writable, if possible. file_check_directory($dir, TRUE); // Save the file. - $dest = $dir .'/'. $language->language .'_'. $data_hash .'.js'; if (file_save_data($data, $dest)) { $language->javascript = $data_hash; - $status = ($status == 'deleted') ? 'updated' : 'created'; + $status = ($status == 'deleted') ? 'updated' : ($changed_hash ? 'created' : 'rebuilt'); } else { $language->javascript = ''; @@ -2204,8 +2208,9 @@ } // Save the new JavaScript hash (or an empty value if the file - // just got deleted). Act only if some operation was executed. - if ($status) { + // just got deleted). Act only if some operation was executed that + // changed the hash code. + if ($status && $changed_hash) { db_query("UPDATE {languages} SET javascript = '%s' WHERE language = '%s'", $language->javascript, $language->language); // Update the default language variable if the default language has been altered. @@ -2223,6 +2228,9 @@ case 'updated': watchdog('locale', 'Updated JavaScript translation file for the language %language.', array('%language' => t($language->name))); return TRUE; + case 'rebuilt': + watchdog('locale', 'JavaScript translation file %file.js was lost.', array('%file' => $language->javascript), WATCHDOG_WARNING); + // let slip through case 'created': watchdog('locale', 'Created JavaScript translation file for the language %language.', array('%language' => t($language->name))); return TRUE;