summaryrefslogtreecommitdiff
path: root/includes/locale.inc
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-10-15 15:18:39 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-10-15 15:18:39 +0000
commit1e8ddda9b78365f66019c0443669557562e030ed (patch)
tree049ba636ffa046e85c8ef0f351c847dd887958ab /includes/locale.inc
parent19322c375bd5cc6b8d230cbef561bcf86e744bd9 (diff)
downloadbrdo-1e8ddda9b78365f66019c0443669557562e030ed.tar.gz
brdo-1e8ddda9b78365f66019c0443669557562e030ed.tar.bz2
#169079 by yched: improve consistency of menu API and batch API by allowing batch definition in non .module files, which opens the possibility of better performing batches (which are likely to reside in .admin.inc files generally)
- apply this change in locale.module - improve batch API code documentation
Diffstat (limited to 'includes/locale.inc')
-rw-r--r--includes/locale.inc105
1 files changed, 72 insertions, 33 deletions
diff --git a/includes/locale.inc b/includes/locale.inc
index caa345765..d033d119e 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -2420,7 +2420,6 @@ function _locale_get_predefined_list() {
* A batch structure or FALSE if no files found.
*/
function locale_batch_by_language($langcode, $finished = '_locale_batch_installer_finished') {
-
// Collect all files to import for all enabled modules and themes.
$files = array();
$result = db_query("SELECT name, filename FROM {system} WHERE status = 1");
@@ -2436,6 +2435,39 @@ function locale_batch_by_language($langcode, $finished = '_locale_batch_installe
}
/**
+ * 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');
+ 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");
+ while ($component = db_fetch_object($result)) {
+ 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('.', '..', 'CVS'), 0, FALSE));
+ }
+ }
+ return _locale_batch_build($files, $finished);
+ }
+ return FALSE;
+}
+
+/**
* Build a locale batch from an array of files.
*
* @param $files
@@ -2457,6 +2489,7 @@ function _locale_batch_build($files, $finished = NULL) {
'title' => $t('Importing interface translations'),
'init_message' => $t('Starting import'),
'error_message' => $t('Error importing interface translations'),
+ 'file' => './includes/locale.inc',
);
if (isset($finished)) {
$batch['finished'] = $finished;
@@ -2467,45 +2500,51 @@ function _locale_batch_build($files, $finished = NULL) {
}
/**
- * Batch callback invoked when installer import processing finishes.
- * Advance installer task to the finished screen.
+ * Perform interface translation import as a batch step.
+ *
+ * @param $filepath
+ * Path to a file to import.
+ * @param $results
+ * Contains a list of files imported.
+ */
+function _locale_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)) {
+ $file = (object) array('filename' => basename($filepath), 'filepath' => $filepath);
+ _locale_import_read_po('db-store', $file, LOCALE_IMPORT_KEEP, $langcode[2]);
+ $context['results'][] = $filepath;
+ }
+}
+
+/**
+ * Finished callback of system page locale import batch.
+ * Inform the user of translation files imported.
*/
-function _locale_batch_installer_finished($success, $results) {
- variable_set('install_task', 'finished');
+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.'));
+ }
}
/**
- * 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.
+ * Finished callback of language addition locale import batch.
+ * Inform the user of translation files imported.
*/
-function locale_batch_by_component($components, $finished = '_locale_batch_system_finished') {
- $files = array();
- $languages = language_list('enabled');
- 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");
- while ($component = db_fetch_object($result)) {
- 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('.', '..', 'CVS'), 0, FALSE));
- }
- }
- return _locale_batch_build($files, $finished);
+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.'));
}
- return FALSE;
}
+
+/**
+ * Finished callback of installer locale import batch.
+ * Advance installer task to the finished screen.
+ */
+function _locale_batch_installer_finished($success, $results) {
+ variable_set('install_task', 'finished');
+}
+
/**
* @} End of "locale-autoimport"
*/