function locale_translation_status_save
Same name in other branches
- 9 core/modules/locale/locale.module \locale_translation_status_save()
- 8.9.x core/modules/locale/locale.module \locale_translation_status_save()
- 11.x core/modules/locale/locale.module \locale_translation_status_save()
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.
object $data: File object also containing timestamp when the translation is last updated.
4 calls to locale_translation_status_save()
- locale_translation_batch_fetch_download in core/
modules/ locale/ locale.batch.inc - Implements callback_batch_operation().
- locale_translation_batch_fetch_import in core/
modules/ locale/ locale.batch.inc - Implements callback_batch_operation().
- locale_translation_batch_status_check in core/
modules/ locale/ locale.batch.inc - Implements callback_batch_operation().
- locale_translation_check_projects_local in core/
modules/ locale/ locale.compare.inc - Check and store the status and timestamp of local po files.
File
-
core/
modules/ locale/ locale.module, line 882
Code
function locale_translation_status_save($project, $langcode, $type, $data) {
// Load the translation status or build it if not already available.
\Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.translation');
$status = locale_translation_get_status([
$project,
]);
if (empty($status)) {
$projects = locale_translation_get_projects([
$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])) {
$request_time = \Drupal::time()->getRequestTime();
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::keyValue('locale.translation_status')->set($project, $status[$project]);
\Drupal::state()->set('locale.translation_last_checked', $request_time);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.