function DrushMakeProject::getTranslations

8.0.x make.project.inc DrushMakeProject::getTranslations($project_directory)
6.x make.project.inc DrushMakeProject::getTranslations($project_directory)
7.x make.project.inc DrushMakeProject::getTranslations($project_directory)
5.x make.project.inc DrushMakeProject::getTranslations($project_directory)
master make.project.inc DrushMakeProject::getTranslations($project_directory)

Retrieve translations for this project.

1 call to DrushMakeProject::getTranslations()
DrushMakeProject::make in commands/make/make.project.inc
Build a project.
1 method overrides DrushMakeProject::getTranslations()
DrushMakeProject_Library::getTranslations in commands/make/make.project.inc
No translations for libraries.

File

commands/make/make.project.inc, line 340
Drush Make processing classes.

Class

DrushMakeProject
The base project class.

Code

function getTranslations($project_directory) {
  static $cache = array();
  $langcodes = $this->translations;
  if ($langcodes && in_array($this->type, array('core', 'module', 'profile', 'theme'), TRUE)) {
    // Support the l10n_path, l10n_url keys from l10n_update. Note that the
    // l10n_server key is not supported.
    if (isset($this->l10n_path)) {
      $update_url = $this->l10n_path;
    }
    else {
      if (isset($this->l10n_url)) {
        $l10n_server = $this->l10n_url;
      }
      else {
        $l10n_server = FALSE;
      }
      if ($l10n_server) {
        if (!isset($cache[$l10n_server])) {
          if ($filename = _make_download_file($l10n_server)) {
            $server_info = simplexml_load_string(file_get_contents($filename));
            $cache[$l10n_server] = !empty($server_info->update_url) ? $server_info->update_url : FALSE;
          }
        }
        if ($cache[$l10n_server]) {
          $update_url = $cache[$l10n_server];
        }
        else {
          make_error('XML_ERROR', dt("Could not retrieve l10n update url for !project.", array('!project' => $project['name'])));
          return FALSE;
        }
      }
    }
    if ($update_url) {
      $failed = array();
      foreach ($langcodes as $langcode) {
        $variables = array(
          '%project' => $this->name,
          '%release' => $this->download['full_version'],
          '%core' => $this->core,
          '%language' => $langcode,
          '%filename' => '%filename',
        );
        $url = strtr($update_url, $variables);

        // Download the translation file.  Since its contents are volatile,
        // cache for only 4 hours.
        if ($filename = _make_download_file($url,  * )) {
          // If this is the core project type, download the translation file
          // and place it in every profile and an additional copy in
          // modules/system/translations where it can be detected for import
          // by other non-default install profiles.
          if ($this->type === 'core') {
            $profiles = drush_scan_directory($project_directory . '/profiles', '/.*/', array(), , FALSE, 'filename', , TRUE);
            foreach ($profiles as $profile) {
              if (is_dir($project_directory . '/profiles/' . $profile->basename)) {
                drush_mkdir($project_directory . '/profiles/' . $profile->basename . '/translations');
                drush_copy_dir($filename, $project_directory . '/profiles/' . $profile->basename . '/translations/' . $langcode . '.po');
              }
            }
            drush_mkdir($project_directory . '/modules/system/translations');
            drush_copy_dir($filename, $project_directory . '/modules/system/translations/' . $langcode . '.po');
          }
          else {
            drush_mkdir($project_directory . '/translations');
            drush_copy_dir($filename, $project_directory . '/translations/' . $langcode . '.po', TRUE);
          }
        }
        else {
          $failed[] = $langcode;
        }
      }
      if (empty($failed)) {
        drush_log('All translations downloaded for ' . $this->name, 'ok');
      }
      else {
        drush_log('Unable to download translations for ' . $this->name . ': ' . implode(', ', $failed), 'warning');
      }
    }
  }
  return TRUE;
}