locale_translation_status_save

locale_translation_status_save($project, $langcode, $type, $data)

Saves the status of translation sources in static cache.

Parameters

string $project: Machine readable project name.

string $langcode: Language code.

string $type: Type of data to be stored.

array $data: File object also containing timestamp when the translation is last updated.

File

core/modules/locale/locale.module, line 919
Enables the translation of the user interface to languages other than English.

Code

function locale_translation_status_save($project, $langcode, $type, $data) {
  // Follow-up issue: https://www.drupal.org/node/1842362.
  // Split status storage per module/language and expire individually. This will
  // improve performance for large sites.

  // Load the translation status or build it if not already available.
  module_load_include('translation.inc', 'locale');
  $status = locale_translation_get_status();
  if (empty($status)) {
    $projects = locale_translation_get_projects(array($project));
    if (isset($projects[$project])) {
      $status[$project][$langcode] = locale_translation_source_build($projects[$project], $langcode);
    }
  }

  // Merge the new status data with the existing status.
  if (isset($status[$project][$langcode])) {
    switch ($type) {
      case LOCALE_TRANSLATION_REMOTE:
      case LOCALE_TRANSLATION_LOCAL:
        // Add the source data to the status array.
        $status[$project][$langcode]->files[$type] = $data;

        // Check if this translation is the most recent one. Set timestamp and
        // data type of the most recent translation source.
        if (isset($data->timestamp) && $data->timestamp) {
          if ($data->timestamp > $status[$project][$langcode]->timestamp) {
            $status[$project][$langcode]->timestamp = $data->timestamp;
            $status[$project][$langcode]->last_checked = REQUEST_TIME;
            $status[$project][$langcode]->type = $type;
          }
        }
        break;

      case LOCALE_TRANSLATION_CURRENT:
        $data->last_checked = REQUEST_TIME;
        $status[$project][$langcode]->timestamp = $data->timestamp;
        $status[$project][$langcode]->last_checked = $data->last_checked;
        $status[$project][$langcode]->type = $type;
        locale_translation_update_file_history($data);
        break;
    }

    \Drupal::state()->set('locale.translation_status', $status);
    \Drupal::state()->set('locale.translation_last_checked', REQUEST_TIME);
  }
}
doc_Drupal
2016-10-29 09:24:28
Comments
Leave a Comment

Please login to continue.