From 0047e35d9137a37235c0248daacaad70ed0105da Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Tue, 22 May 2007 07:42:37 +0000 Subject: [PATCH] - Patch #145671 by Gabor: import translation files when adding a new language. --- CHANGELOG.txt | 2 ++ includes/locale.inc | 25 ++++++++++++++++++------- install.php | 2 +- modules/locale/locale.module | 12 +++++++++++- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ef6c7d099fc..de22887f57d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -21,6 +21,8 @@ Drupal 6.0, xxxx-xx-xx (development version) * Browser based language detection. * Made it possible to specify a node's language. * Language dependent path aliases. + * Automatically import translations when enabling new modules. + * Automatically import translations when adding a new language. - Moved "PHP input filter" to a stand-alone module so it can be deleted for security reasons. - Usability: * Improved handling of teasers in posts. diff --git a/includes/locale.inc b/includes/locale.inc index bc8ea7503f1..1fba748bc7a 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -303,6 +303,12 @@ function locale_languages_predefined_form_submit($form_values, $form, &$form_sta drupal_set_message(t('The language %language has been created and can now be used. More information is available on the help screen.', array('%language' => t($predefined[$langcode][0]), '@locale-help' => url('admin/help/locale')))); } + // See if we have language files to import for the newly added + // language, collect and import them. + if ($batch = locale_batch_by_language($langcode, '_locale_batch_language_finished')) { + batch_set($batch); + } + $form_state['redirect'] = 'admin/settings/language'; return; } @@ -848,7 +854,7 @@ function locale_translate_delete($lid) { * @param $default * Optionall set this language to be the default. */ -function locale_add_language($langcode, $name = NULL, $native = NULL, $direction = LANGUAGE_LTR, $domain = '', $prefix = '', $enabled = FALSE, $default = FALSE) { +function locale_add_language($langcode, $name = NULL, $native = NULL, $direction = LANGUAGE_LTR, $domain = '', $prefix = '', $enabled = TRUE, $default = FALSE) { // Default prefix on language code. if (empty($prefix)) { $prefix = $langcode; @@ -2111,14 +2117,17 @@ function _locale_get_predefined_list() { */ /** - * Prepare a batch to use to import translations on install time. + * Prepare a batch to import translations for all enabled + * modules in a given language. * * @param $langcode * Language code to import translations for. + * @param $finished + * Optional finished callback for the batch. * @return * A batch structure or FALSE if no files found. */ -function locale_batch_installer($langcode) { +function locale_batch_by_language($langcode, $finished = '_locale_batch_installer_finished') { // Collect all files to import for all enabled modules and themes. $files = array(); @@ -2131,7 +2140,7 @@ function locale_batch_installer($langcode) { $files = array_merge($files, file_scan_directory(dirname($component->filename) .'/po/', '(^|\.)'. $langcode .'\.po$', array('.', '..', 'CVS'), 0, FALSE)); } - return _locale_batch_build($files, '_locale_batch_installer_finished'); + return _locale_batch_build($files, $finished); } /** @@ -2140,7 +2149,7 @@ function locale_batch_installer($langcode) { * @param $files * Array of files to import * @param $finished - * A finished callback to use for the batch + * Optional finished callback for the batch. * @return * A batch structure */ @@ -2181,8 +2190,10 @@ function _locale_batch_installer_finished($success, $results) { * @param $components * An array of component (theme and/or module) names to import * translations for. + * @param $finished + * Optional finished callback for the batch. */ -function locale_batch_system($components) { +function locale_batch_by_component($components, $finished = '_locale_batch_system_finished') { $files = array(); $languages = language_list('enabled'); unset($languages[1]['en']); @@ -2199,7 +2210,7 @@ function locale_batch_system($components) { $files = array_merge($files, file_scan_directory(dirname($component->filename) .'/po/', '(^|\.)('. $language_list .')\.po$', array('.', '..', 'CVS'), 0, FALSE)); } } - return _locale_batch_build($files, '_locale_batch_system_finished'); + return _locale_batch_build($files, $finished); } return FALSE; } diff --git a/install.php b/install.php index f68b0fffc37..aa51aabb186 100644 --- a/install.php +++ b/install.php @@ -676,7 +676,7 @@ function install_tasks($profile, $task) { // Enable installation language as default site language. locale_add_language($install_locale, NULL, NULL, NULL, NULL, NULL, 1, TRUE); // Collect files to import for this language. - $batch = locale_batch_installer($install_locale); + $batch = locale_batch_by_language($install_locale); if (!empty($batch)) { // Start a batch, switch to 'locale-batch' task. We need to // set the variable here, because batch_process() redirects. diff --git a/modules/locale/locale.module b/modules/locale/locale.module index e5f952e25a2..8d826fd5589 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -437,7 +437,7 @@ function locale_language_list($field = 'name', $all = FALSE) { */ function locale_system_update($components) { include_once 'includes/locale.inc'; - if ($batch = locale_batch_system($components)) { + if ($batch = locale_batch_by_component($components)) { batch_set($batch); } } @@ -452,6 +452,16 @@ function _locale_batch_system_finished($success, $results) { } } +/** + * Finished callback of language addition locale import batch. + * Inform the user of translation files imported. + */ +function _locale_batch_language_finished($success, $results) { + if ($success) { + drupal_set_message(format_plural(count($results), 'One translation file imported for the enabled modules.', '@count translation files imported for the enabled modules.')); + } +} + /** * Perform interface translation import as a batch step. *