diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-04 04:53:33 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-04 04:53:33 +0000 |
commit | 83e15a3f9ad691e8450a5017f0627f9582097e0f (patch) | |
tree | a9c75ed1b261a9c340cdf19443ea9e659f16cccf /includes | |
parent | ea064e3e8fffa3d9de435f801a489de7a95af14a (diff) | |
download | brdo-83e15a3f9ad691e8450a5017f0627f9582097e0f.tar.gz brdo-83e15a3f9ad691e8450a5017f0627f9582097e0f.tar.bz2 |
#338630 by plach, dagmar, David Koudela, arhak, et al: Enable Locale to rebuild lost Javascript translation files.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/locale.inc | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/includes/locale.inc b/includes/locale.inc index 07d6d75bf..9b1e95b9a 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -2913,6 +2913,7 @@ function _locale_rebuild_js($langcode = NULL) { } // Construct the JavaScript file, if there are translations. + $data_hash = NULL; $data = $status = ''; if (!empty($translations)) { @@ -2931,22 +2932,38 @@ function _locale_rebuild_js($langcode = NULL) { $dir = 'public://' . variable_get('locale_js_directory', 'languages'); // 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)) { + $changed_hash = $language->javascript != $data_hash; + if (!empty($language->javascript) && (!$data || $changed_hash)) { file_unmanaged_delete($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_prepare_directory($dir, FILE_CREATE_DIRECTORY); // Save the file. - $dest = $dir . '/' . $language->language . '_' . $data_hash . '.js'; if (file_unmanaged_save_data($data, $dest)) { $language->javascript = $data_hash; - $status = ($status == 'deleted') ? 'updated' : 'created'; + // If we deleted a previous version of the file and we replace it with a + // new one we have an update. + if ($status == 'deleted') { + $status = 'updated'; + } + // If the file did not exist previously and the data has changed we have + // a fresh creation. + elseif ($changed_hash) { + $status = 'created'; + } + // If the data hash is unchanged the translation was lost and has to be + // rebuilt. + else { + $status = 'rebuilt'; + } } else { $language->javascript = ''; @@ -2954,9 +2971,10 @@ function _locale_rebuild_js($langcode = NULL) { } } - // Save the new JavaScript hash (or an empty value if the file - // just got deleted). Act only if some operation was executed. - if ($status) { + // Save the new JavaScript hash (or an empty value if the file just got + // deleted). Act only if some operation was executed that changed the hash + // code. + if ($status && $changed_hash) { db_update('languages') ->fields(array( 'javascript' => $language->javascript, @@ -2979,6 +2997,10 @@ function _locale_rebuild_js($langcode = NULL) { 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); + // Proceed to the 'created' case as the JavaScript translation file has + // been created again. case 'created': watchdog('locale', 'Created JavaScript translation file for the language %language.', array('%language' => t($language->name))); return TRUE; |