From 112aa20768d6e61da97e5883b0e91562fa4a3d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= Date: Mon, 21 May 2007 10:56:05 +0000 Subject: #144496 by myself: import translations for newly installed modules and enabled themes; as a side effect, improve usability of the module screen by performing module changes all at once --- modules/locale/locale.module | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'modules/locale') diff --git a/modules/locale/locale.module b/modules/locale/locale.module index 2bd65463e..e5f952e25 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -424,3 +424,49 @@ function locale_language_list($field = 'name', $all = FALSE) { } return $list; } + +/** + * Imports translations when new modules or themes are installed or enabled. + * + * This function will either import translation for the component change + * right away, or start a batch if more files need to be imported. + * + * @param $components + * An array of component (theme and/or module) names to import + * translations for. + */ +function locale_system_update($components) { + include_once 'includes/locale.inc'; + if ($batch = locale_batch_system($components)) { + batch_set($batch); + } +} + +/** + * 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.')); + } +} + +/** + * 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) { + include_once 'includes/locale.inc'; + // 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, 'keep', $langcode[2]); + $context['results'][] = $filepath; + } +} -- cgit v1.2.3