Commit 0047e35d authored by Dries's avatar Dries

- Patch #145671 by Gabor: import translation files when adding a new language.

parent 5094312d
......@@ -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.
......
......@@ -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 <a href="@locale-help">help screen</a>.', 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;
}
......
......@@ -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.
......
......@@ -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.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment