Check and store the status and timestamp of local po files.
Only po files in the local file system are checked. Any remote translation sources will be ignored. Results are stored in the state variable 'locale.translation_status'.
Projects may contain a server_pattern option containing a pattern of the path to the po source files. If no server_pattern is defined the default translation directory is checked for the po file. When a server_pattern is defined the specified location is checked. The server_pattern can be set in the module's .info.yml file or by using hook_locale_translation_projects_alter().
array $projects: Array of project names for which to check the state of translation files. Defaults to all translatable projects.
array $langcodes: Array of language codes. Defaults to all translatable languages.
function locale_translation_check_projects_local($projects = array(), $langcodes = array()) {
$projects = locale_translation_get_projects($projects);
$langcodes = $langcodes ? $langcodes : array_keys(locale_translatable_language_list());
$history = locale_translation_get_file_history();
$results = array();
// For each project and each language we check if a local po file is
// available. When found the source object is updated with the appropriate
// type and timestamp of the po file.
foreach ($projects as $name => $project) {
foreach ($langcodes as $langcode) {
$source = locale_translation_source_build($project, $langcode);
if (locale_translation_source_check_file($source)) {
$source->type = 'local';
$source->timestamp = $source->files['local']->timestamp;
}
// Compare the available translation with the current translations status.
// If the project/language was translated before and it is more recent
// than the most recent translation, the translation is up to date. Which
// is marked in the source object with type "current".
if (isset($history[$source->project][$source->langcode])) {
$current = $history[$source->project][$source->langcode];
// Add the current translation to the source object to save it in
// the status cache.
$source->files[LOCALE_TRANSLATION_CURRENT] = $current;
if (isset($source->type)) {
$available = $source->files[$source->type];
$result = _locale_translation_source_compare($current, $available) == LOCALE_TRANSLATION_SOURCE_COMPARE_LT ? $available : $current;
$source->type = $result->type;
$source->timestamp = $result->timestamp;
}
else {
$source->type = $current->type;
$source->timestamp = $current->timestamp;
}
}
$results[$name][$langcode] = $source;
}
}
locale_translation_status_save($results);
}