function locale_translation_status_save in Drupal 9
Same name and namespace in other branches
- 8 core/modules/locale/locale.module \locale_translation_status_save()
- 10 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 900 - Enables the translation of the user interface to languages other than English.
Code
function locale_translation_status_save($project, $langcode, $type, $data) {
// 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([
$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::keyValue('locale.translation_status')
->set($project, $status[$project]);
\Drupal::state()
->set('locale.translation_last_checked', REQUEST_TIME);
}
}