diff --git a/includes/common.inc b/includes/common.inc index 34fa9b9..c39d543 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -897,13 +897,6 @@ function drupal_http_request($url, array $options = array()) { // clash with the HTTP status codes. $result->code = -$errno; $result->error = trim($errstr) ? trim($errstr) : t('Error opening socket @socket', array('@socket' => $socket)); - - // Mark that this request failed. This will trigger a check of the web - // server's ability to make outgoing HTTP requests the next time that - // requirements checking is performed. - // See system_requirements(). - variable_set('drupal_http_request_fails', TRUE); - return $result; } @@ -5079,6 +5072,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/includes/locale.inc b/includes/locale.inc index 82c55e5..a43a068 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -597,7 +597,7 @@ function locale_add_language($langcode, $name = NULL, $native = NULL, $direction drupal_static_reset('language_list'); // Force JavaScript translation file creation for the newly added language. - _locale_invalidate_js($langcode); + _locale_rebuild_js($langcode); watchdog('locale', 'The %language language (%code) has been created.', array('%language' => $name, '%code' => $langcode)); @@ -655,7 +655,7 @@ function _locale_import_po($file, $langcode, $mode, $group = NULL) { } // Clear cache and force refresh of JavaScript translations. - _locale_invalidate_js($langcode); + _locale_rebuild_js($langcode); cache_clear_all('locale:', 'cache', TRUE); // Rebuild the menu, strings may have changed. @@ -1961,40 +1961,6 @@ function _locale_translate_seek_query() { } /** - * 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(); - 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 $language @@ -2077,6 +2043,10 @@ function _locale_rebuild_js($langcode = NULL) { $status = 'error'; } } + if (!$data && $changed_hash) { + $language->javascript = FALSE; + $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/modules/locale/locale.admin.inc b/modules/locale/locale.admin.inc index e813962..58da7a5 100644 --- a/modules/locale/locale.admin.inc +++ b/modules/locale/locale.admin.inc @@ -1220,15 +1220,12 @@ function locale_translate_edit_form_submit($form, &$form_state) { ->condition('language', $key) ->execute(); } - - // Force JavaScript translation file recreation for this language. - _locale_invalidate_js($key); } drupal_set_message(t('The string has been saved.')); - // Clear locale cache. - _locale_invalidate_js(); + // Clear locale cache and rebuild JavaScript translations. + _locale_rebuild_js(); cache_clear_all('locale:', 'cache', TRUE); $form_state['redirect'] = 'admin/config/regional/translate/translate'; @@ -1264,7 +1261,7 @@ function locale_translate_delete_form_submit($form, &$form_state) { ->condition('lid', $form_state['values']['lid']) ->execute(); // Force JavaScript translation file recreation for all languages. - _locale_invalidate_js(); + _locale_rebuild_js(); cache_clear_all('locale:', 'cache', TRUE); drupal_set_message(t('The string has been removed.')); $form_state['redirect'] = 'admin/config/regional/translate/translate'; diff --git a/modules/locale/locale.module b/modules/locale/locale.module index 768fead..0a2d587 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -922,34 +922,26 @@ 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->language])) { - // Don't clear the refresh flag on failure, so that another try will - // be performed later. - if (_locale_rebuild_js()) { - unset($parsed['refresh:' . $language->language]); - } - // 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. - if ($files && !empty($language->javascript)) { + // Translate JavaScript files for non-English. + if ($language->language != 'en') { + // If there has not been an attempt to generate a JavaScript file, try now. + if ($language->javascript === '') { + _locale_rebuild_js($language->language); + } // Add the translation JavaScript file to the page. - $file = $dir . '/' . $language->language . '_' . $language->javascript . '.js'; - $javascript[$file] = drupal_js_defaults($file); + if ($files && !empty($language->javascript)) { + // Add the translation JavaScript file to the page. + $file = $dir . '/' . $language->language . '_' . $language->javascript . '.js'; + if (!file_exists($files)) { + _locale_rebuild_js($language->language); + } + $javascript[$file] = drupal_js_defaults($file); + } } }