diff --git a/core/includes/common.inc b/core/includes/common.inc index 0b95dcd..69f59cd 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -4989,6 +4989,9 @@ function drupal_build_js_cache($files) { */ function drupal_clear_js_cache() { variable_del('javascript_parsed'); + variable_del('locale_js_files'); + $dir = 'public://' . variable_get('locale_js_directory', 'languages'); + file_unmanaged_delete_recursive($dir); variable_del('drupal_js_cache_files'); file_scan_directory('public://js', '/.*/', array('callback' => 'drupal_delete_file_if_stale')); } diff --git a/core/includes/gettext.inc b/core/includes/gettext.inc index ef9d25d..4fa270f 100644 --- a/core/includes/gettext.inc +++ b/core/includes/gettext.inc @@ -57,7 +57,7 @@ function _locale_import_po($file, $langcode, $overwrite_options, $customized = L } // Clear cache and force refresh of JavaScript translations. - _locale_invalidate_js($langcode); + _locale_rebuild_js($langcode); cache()->deletePrefix('locale:'); // Rebuild the menu, strings may have changed. diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index ce20b59..fd81d3d 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -176,8 +176,6 @@ function locale_language_insert($language) { // @todo move these two cache clears out. See http://drupal.org/node/1293252 // Changing the language settings impacts the interface. cache('page')->flush(); - // Force JavaScript translation file re-creation for the new language. - _locale_invalidate_js($language->langcode); } /** @@ -188,7 +186,7 @@ function locale_language_update($language) { // Changing the language settings impacts the interface. cache('page')->flush(); // Force JavaScript translation file re-creation for the modified language. - _locale_invalidate_js($language->langcode); + _locale_rebuild_js($language->langcode); } /** @@ -204,8 +202,6 @@ function locale_language_delete($language) { module_load_include('inc', 'locale', 'locale.bulk'); locale_translate_delete_translation_files($language->langcode); - _locale_invalidate_js($language->langcode); - // Changing the language settings impacts the interface: cache('page')->flush(); @@ -387,34 +383,24 @@ function locale_js_alter(&$javascript) { } } - // If there are any new source files we parsed, invalidate existing - // JavaScript translation files for all languages, adding the refresh - // flags into the existing array. + // If there are any new source files we parsed, store them so that they will + // not be parsed on the next request. if ($new_files) { - $parsed += _locale_invalidate_js(); - } - - // If necessary, rebuild the translation file for the current language. - if (!empty($parsed['refresh:' . $language_interface->langcode])) { - // Don't clear the refresh flag on failure, so that another try will - // be performed later. - if (_locale_rebuild_js()) { - unset($parsed['refresh:' . $language_interface->langcode]); - } - // Store any changes after refresh was attempted. - variable_set('javascript_parsed', $parsed); - } - // If no refresh was attempted, but we have new source files, we need - // to store them too. This occurs if current page is in English. - elseif ($new_files) { variable_set('javascript_parsed', $parsed); } // Add the translation JavaScript file to the page. $locale_javascripts = variable_get('locale_translation_javascript', array()); + // If no translation file exists, build it now. + if (!isset($locale_javascripts[$language_interface->langcode])) { + _locale_rebuild_js($language_interface->langcode); + } if ($files && !empty($locale_javascripts[$language_interface->langcode])) { // Add the translation JavaScript file to the page. $file = $dir . '/' . $language_interface->langcode . '_' . $locale_javascripts[$language_interface->langcode] . '.js'; + if (!file_exists($file)) { + _locale_rebuild_js($language_interface->langcode); + } $javascript[$file] = drupal_js_defaults($file); } } @@ -728,42 +714,6 @@ function _locale_parse_js_file($filepath) { } /** - * Force the JavaScript translation file(s) to be refreshed. - * - * This function sets a refresh flag for a specified language, or all - * languages except English, if none specified. JavaScript translation - * files are rebuilt (with locale_update_js_files()) the next time a - * request is served in that language. - * - * @param $langcode - * The language code for which the file needs to be refreshed. - * - * @return - * New content of the 'javascript_parsed' variable. - */ -function _locale_invalidate_js($langcode = NULL) { - $parsed = variable_get('javascript_parsed', array()); - - if (empty($langcode)) { - // Invalidate all languages. - $languages = language_list(); - if (!locale_translate_english()) { - unset($languages['en']); - } - foreach ($languages as $lcode => $data) { - $parsed['refresh:' . $lcode] = 'waiting'; - } - } - else { - // Invalidate single language. - $parsed['refresh:' . $langcode] = 'waiting'; - } - - variable_set('javascript_parsed', $parsed); - return $parsed; -} - -/** * (Re-)Creates the JavaScript translation file for a language. * * @param $langcode @@ -848,6 +798,10 @@ function _locale_rebuild_js($langcode = NULL) { $status = 'error'; } } + if (!$data && ($changed_hash)) { + $locale_javascripts[$language->langcode] = NULL; + $status = 'deleted'; + } // 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 diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index b91d3a4..8d5866b 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -443,8 +443,8 @@ function locale_translate_edit_form_submit($form, &$form_state) { $form_state['redirect'] = array('admin/config/regional/translate', array('query' => array('page' => $_GET['page']))); } - // Force JavaScript translation file recreation for this language. - _locale_invalidate_js($langcode); + // Rebuild the JavaScript translation file for this language. + _locale_rebuild_js($langcode); // Clear locale cache. cache()->deletePrefix('locale:'); }