diff options
author | catch <catch@35733.no-reply.drupal.org> | 2011-10-29 20:40:09 +0900 |
---|---|---|
committer | catch <catch@35733.no-reply.drupal.org> | 2011-10-29 20:40:09 +0900 |
commit | dbbdfee944ef29f554bad36cacddc6b50d1c4dec (patch) | |
tree | 7e27723d7b6c5adbbb9589d47178bc451fbfa64d /modules | |
parent | ecff4bd201f37d6f00dc375b1d40ff2d1f883c26 (diff) | |
download | drupal-dbbdfee944ef29f554bad36cacddc6b50d1c4dec.tar.gz drupal-dbbdfee944ef29f554bad36cacddc6b50d1c4dec.zip |
Issue #1260586 by Gábor Hojtsy, tstoeckler, good_man: Consolidate .po file import to one directory..
Diffstat (limited to 'modules')
-rw-r--r-- | modules/locale/locale.admin.inc | 2 | ||||
-rw-r--r-- | modules/locale/locale.bulk.inc | 119 | ||||
-rw-r--r-- | modules/locale/locale.module | 28 | ||||
-rw-r--r-- | modules/locale/locale.test | 5 | ||||
-rw-r--r-- | modules/locale/tests/test.xx.po (renamed from modules/locale/tests/translations/test.xx.po) | 0 |
5 files changed, 56 insertions, 98 deletions
diff --git a/modules/locale/locale.admin.inc b/modules/locale/locale.admin.inc index 6abe48b1dbf..90d46cae83d 100644 --- a/modules/locale/locale.admin.inc +++ b/modules/locale/locale.admin.inc @@ -379,7 +379,7 @@ function locale_languages_add_set_batch($langcode) { // See if we have language files to import for the newly added // language, collect and import them. include_once drupal_get_path('module', 'locale') . '/locale.bulk.inc'; - if ($batch = locale_batch_by_language($langcode, '_locale_batch_language_finished')) { + if ($batch = locale_translate_batch_import_files($langcode, TRUE)) { batch_set($batch); } } diff --git a/modules/locale/locale.bulk.inc b/modules/locale/locale.bulk.inc index ce10f05cba5..969ea6764bf 100644 --- a/modules/locale/locale.bulk.inc +++ b/modules/locale/locale.bulk.inc @@ -167,99 +167,42 @@ function locale_translate_export_po_form_submit($form, &$form_state) { } /** - * Prepare a batch to import translations for all enabled - * modules in a given language. + * Prepare a batch to import all translations. * * @param $langcode - * Language code to import translations for. - * @param $finished - * Optional finished callback for the batch. - * @param $skip - * Array of component names to skip. Used in the installer for the - * second pass import, when most components are already imported. + * (optional) Language code to limit files being imported. + * @param $finish_feedback + * (optional) Whether to give feedback to the user when finished. * - * @return - * A batch structure or FALSE if no files found. + * @todo + * Integrate with update status to identify projects needed and integrate + * l10n_update functionality to feed in translation files alike. + * See http://drupal.org/node/1191488. */ -function locale_batch_by_language($langcode, $finished = NULL, $skip = array()) { - // Collect all files to import for all enabled modules and themes. - $files = array(); - $components = array(); - $query = db_select('system', 's'); - $query->fields('s', array('name', 'filename')); - $query->condition('s.status', 1); - if (count($skip)) { - $query->condition('name', $skip, 'NOT IN'); - } - $result = $query->execute(); - foreach ($result as $component) { - // Collect all files for all components, names as $langcode.po or - // with names ending with $langcode.po. This allows for filenames - // like node-module.de.po to let translators use small files and - // be able to import in smaller chunks. - $files = array_merge($files, file_scan_directory(dirname($component->filename) . '/translations', '/(^|\.)' . $langcode . '\.po$/', array('recurse' => FALSE))); - $components[] = $component->name; - } - - return _locale_batch_build($files, $finished, $components); -} - -/** - * Prepare a batch to run when installing modules or enabling themes. - * - * This batch will import translations for the newly added components - * in all the languages already set up on the site. - * - * @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_by_component($components, $finished = '_locale_batch_system_finished') { - $files = array(); - $languages = language_list('enabled'); - if (!locale_translate_english()) { - unset($languages[1]['en']); - } - if (count($languages[1])) { - $language_list = join('|', array_keys($languages[1])); - // Collect all files to import for all $components. - $result = db_query("SELECT name, filename FROM {system} WHERE status = 1"); - foreach ($result as $component) { - if (in_array($component->name, $components)) { - // Collect all files for this component in all enabled languages, named - // as $langcode.po or with names ending with $langcode.po. This allows - // for filenames like node-module.de.po to let translators use small - // files and be able to import in smaller chunks. - $files = array_merge($files, file_scan_directory(dirname($component->filename) . '/translations', '/(^|\.)(' . $language_list . ')\.po$/', array('recurse' => FALSE))); - } - } - return _locale_batch_build($files, $finished); - } - return FALSE; +function locale_translate_batch_import_files($langcode = NULL, $finish_feedback = FALSE) { + $directory = variable_get('locale_translate_file_directory', conf_path() . '/files/translations'); + $files = file_scan_directory($directory, '!' . (!empty($langcode) ? '\.' . preg_quote($langcode, '!') : '') . '\.po$!', array('recurse' => FALSE)); + return locale_translate_batch_build($files, $finish_feedback); } /** * Build a locale batch from an array of files. * * @param $files - * Array of files to import. - * @param $finished - * Optional finished callback for the batch. - * @param $components - * Optional list of component names the batch covers. Used in the installer. + * Array of file objects to import. + * @param $finish_feedback + * (optional) Whether to give feedback to the user when finished. * * @return - * A batch structure. + * A batch structure or FALSE if $files was empty. */ -function _locale_batch_build($files, $finished = NULL, $components = array()) { +function locale_translate_batch_build($files, $finish_feedback = FALSE) { $t = get_t(); if (count($files)) { $operations = array(); foreach ($files as $file) { - // We call _locale_batch_import for every batch operation. - $operations[] = array('_locale_batch_import', array($file->uri)); + // We call locale_translate_batch_import for every batch operation. + $operations[] = array('locale_translate_batch_import', array($file->uri)); } $batch = array( 'operations' => $operations, @@ -267,12 +210,9 @@ function _locale_batch_build($files, $finished = NULL, $components = array()) { 'init_message' => $t('Starting import'), 'error_message' => $t('Error importing interface translations'), 'file' => drupal_get_path('module', 'locale') . '/locale.bulk.inc', - // This is not a batch API construct, but data passed along to the - // installer, so we know what did we import already. - '#components' => $components, ); - if (isset($finished)) { - $batch['finished'] = $finished; + if ($finish_feedback) { + $batch['finished'] = 'locale_translate_batch_finished'; } return $batch; } @@ -287,7 +227,7 @@ function _locale_batch_build($files, $finished = NULL, $components = array()) { * @param $results * Contains a list of files imported. */ -function _locale_batch_import($filepath, &$context) { +function locale_translate_batch_import($filepath, &$context) { // The filename is either {langcode}.po or {prefix}.{langcode}.po, so // we can extract the language code to use for the import from the end. if (preg_match('!(/|\.)([^\./]+)\.po$!', $filepath, $langcode)) { @@ -299,20 +239,9 @@ function _locale_batch_import($filepath, &$context) { /** * Finished callback of system page locale import batch. - * Inform the user of translation files imported. - */ -function _locale_batch_system_finished($success, $results) { - if ($success) { - drupal_set_message(format_plural(count($results), 'One translation file imported for the newly installed modules.', '@count translation files imported for the newly installed modules.')); - } -} - -/** - * Finished callback of language addition locale import batch. - * Inform the user of translation files imported. */ -function _locale_batch_language_finished($success, $results) { +function locale_translate_batch_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.')); + drupal_set_message(format_plural(count($results), 'One translation file imported.', '@count translation files imported.')); } } diff --git a/modules/locale/locale.module b/modules/locale/locale.module index 9eab4295d7f..e8cd73699f9 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -851,10 +851,16 @@ function locale_themes_enabled($themes) { * @param $components * An array of component (theme and/or module) names to import * translations for. + * + * @todo + * This currently imports all .po files available, independent of + * $components. Once we integrated with update status for project + * identification, we should revisit and only import files for the + * identified projects for the components. */ function locale_system_update($components) { include_once drupal_get_path('module', 'locale') . '/locale.bulk.inc'; - if ($batch = locale_batch_by_component($components)) { + if ($batch = locale_translate_batch_import_files(NULL, TRUE)) { batch_set($batch); } } @@ -1146,3 +1152,23 @@ function locale_form_locale_languages_edit_form_alter_submit($form, $form_state) function locale_translate_english() { return variable_get('locale_translate_english', FALSE); } + +/** + * Implements hook_form_FORM_ID_alter() for system_file_system_settings(). + * + * Add interface translation directory setting to directories configuration. + */ +function locale_form_system_file_system_settings_alter(&$form, $form_state) { + $form['locale_translate_file_directory'] = array( + '#type' => 'textfield', + '#title' => t('Interface translations directory'), + '#default_value' => variable_get('locale_translate_file_directory', conf_path() . '/files/translations'), + '#maxlength' => 255, + '#description' => t('A local file system path where interface translation files are looked for. This directory must exist.'), + '#after_build' => array('system_check_directory'), + '#weight' => 10, + ); + if ($form['file_default_scheme']) { + $form['file_default_scheme']['#weight'] = 20; + } +} diff --git a/modules/locale/locale.test b/modules/locale/locale.test index 34976ff1c2f..6968380a040 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -720,6 +720,9 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { function setUp() { parent::setUp('locale', 'locale_test'); + // Set the translation file directory. + variable_set('locale_translate_file_directory', drupal_get_path('module', 'locale_test')); + $this->admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages')); $this->drupalLogin($this->admin_user); } @@ -830,7 +833,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { // Ensure the translation file was automatically imported when language was // added. - $this->assertText(t('One translation file imported for the enabled modules.'), t('Language file automatically imported.')); + $this->assertText(t('One translation file imported.'), t('Language file automatically imported.')); // Ensure strings were successfully imported. $search = array( diff --git a/modules/locale/tests/translations/test.xx.po b/modules/locale/tests/test.xx.po index 659a6e3f12b..659a6e3f12b 100644 --- a/modules/locale/tests/translations/test.xx.po +++ b/modules/locale/tests/test.xx.po |