summaryrefslogtreecommitdiff
path: root/modules/locale
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-05-21 10:56:05 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-05-21 10:56:05 +0000
commit112aa20768d6e61da97e5883b0e91562fa4a3d9c (patch)
tree5823e5ccf7f855c4e90af08cd810583010ecbcd1 /modules/locale
parent72e43b4f2238b2b99b759c264c0f1174f2631d55 (diff)
downloadbrdo-112aa20768d6e61da97e5883b0e91562fa4a3d9c.tar.gz
brdo-112aa20768d6e61da97e5883b0e91562fa4a3d9c.tar.bz2
#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
Diffstat (limited to 'modules/locale')
-rw-r--r--modules/locale/locale.module46
1 files changed, 46 insertions, 0 deletions
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;
+ }
+}