locale_batch_by_component

  1. drupal
    1. 6
    2. 8 locale.bulk.inc
    3. 7
Versions
6 – 8 locale_batch_by_component($components, $finished = '_locale_batch_system_finished')

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.

Parameters

$components An array of component (theme and/or module) names to import translations for.

$finished Optional finished callback for the batch.

Related topics

▾ 1 function calls locale_batch_by_component()

locale_system_update in modules/locale/locale.module
Imports translations when new modules or themes are installed.

Code

includes/locale.inc, line 2099

<?php
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");
    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;
}
?>