commit c8dca8efd156c04e0a6b139754faf53ffddb510f Author: Erik Stielstra Date: Tue Dec 4 18:09:09 2012 +0100 #125 diff --git a/core/modules/locale/locale.compare.inc b/core/modules/locale/locale.compare.inc index dc998fb..ec9bfa9 100644 --- a/core/modules/locale/locale.compare.inc +++ b/core/modules/locale/locale.compare.inc @@ -248,7 +248,7 @@ function locale_translation_build_server_pattern($project, $template) { * Available sources indexed by project and language. */ function locale_translation_check_projects($projects = array(), $langcodes = array()) { - if (config('locale.settings')->get('translation.use_source') == LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL) { + if (locale_translation_use_remote_source()) { // Retrieve the status of both remote and local translation sources by // using a batch process. locale_translation_check_projects_batch($projects, $langcodes); @@ -330,8 +330,10 @@ function _locale_translation_batch_status_operations($projects, $langcodes) { // Set the batch processes for remote sources. $sources = locale_translation_build_sources($projects, $langcodes); - foreach ($sources as $source) { - $operations[] = array('locale_translation_batch_status_fetch_remote', array($source)); + if (locale_translation_use_remote_source()) { + foreach ($sources as $source) { + $operations[] = array('locale_translation_batch_status_fetch_remote', array($source)); + } } // Check for local sources, compare the results of local and remote and store diff --git a/core/modules/locale/locale.fetch.inc b/core/modules/locale/locale.fetch.inc index 7542086..f6b4927 100755 --- a/core/modules/locale/locale.fetch.inc +++ b/core/modules/locale/locale.fetch.inc @@ -95,10 +95,11 @@ function _locale_translation_fetch_operations($projects, $langcodes, $options) { $config = config('locale.settings'); $operations[] = array('locale_translation_batch_fetch_sources', array($projects, $langcodes)); - foreach ($projects as $project) { foreach ($langcodes as $langcode) { - $operations[] = array('locale_translation_batch_fetch_download', array($project, $langcode)); + if (locale_translation_use_remote_source()) { + $operations[] = array('locale_translation_batch_fetch_download', array($project, $langcode)); + } $operations[] = array('locale_translation_batch_fetch_import', array($project, $langcode, $options)); } } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 366ee09..dac0557 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -318,7 +318,8 @@ function locale_language_delete($language) { _locale_invalidate_js($language->langcode); cache('page')->deleteAll(); - // Clearing all locale cache from database + // Clear locale translation caches. + locale_translation_status_delete_languages(array($language->langcode)); cache()->delete('locale:' . $language->langcode); } @@ -558,7 +559,7 @@ function locale_system_remove($components) { ->execute(); // Clear the translation status. - locale_translation_clear_status(); + locale_translation_status_delete_projects($components); } } } @@ -937,6 +938,42 @@ function locale_translation_status_save($data) { } /** + * Delete language entries from the status cache. + * + * @param array $langcodes + * Language code(s) to be deleted from the cache. + */ +function locale_translation_status_delete_languages($langcodes) { + $status = state()->get('locale.translation_status'); + + foreach ($status as $project => $languages) { + foreach ($languages as $langcode => $source) { + if (in_array($langcode, $langcodes)) { + unset($status[$project][$langcode]); + } + } + } + state()->set('locale.translation_status', $status); +} + +/** + * Delete project entries from the status cache. + * + * @param array $projects + * Project name(s) to be deleted from the cache. + */ +function locale_translation_status_delete_projects($projects) { + $status = state()->get('locale.translation_status'); + + foreach ($status as $project => $languages) { + if (in_array($project, $projects)) { + unset($status[$project]); + } + } + state()->set('locale.translation_status', $status); +} + +/** * Clear the translation status cache. */ function locale_translation_clear_status() { @@ -945,6 +982,17 @@ function locale_translation_clear_status() { } /** + * Checks whether remote translation sources are used. + * + * @return bool + * Returns TRUE if remote translations sources should be taken into account + * when checking or importing translation files, FALSE otherwise. + */ +function locale_translation_use_remote_source() { + return config('locale.settings')->get('translation.use_source') == LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL; +} + +/** * Check that a string is safe to be added or imported as a translation. * * This test can be used to detect possibly bad translation strings. It should