You are here

function l10n_update_source_check_file in Localization update 7.2

Same name and namespace in other branches
  1. 6 l10n_update.check.inc \l10n_update_source_check_file()
  2. 7 l10n_update.check.inc \l10n_update_source_check_file()

Checks whether a po file exists in the local filesystem.

It will search in the directory set in the translation source. Which defaults to the "translations://" stream wrapper path. The directory may contain any valid stream wrapper.

The "local" files property of the source object contains the definition of a po file we are looking for. The file name defaults to %project-%release.%language.po. Per project this value can be overridden using the server_pattern directive in the module's .info.yml file or by using hook_l10n_update_projects_alter().

Parameters

object $source: Translation source object.

Return value

object|bool Source file object of the po file, updated with:

  • "uri": File name and path.
  • "timestamp": Last updated time of the po file.

FALSE if the file is not found.

See also

l10n_update_source_build()

2 calls to l10n_update_source_check_file()
l10n_update_batch_status_check in ./l10n_update.batch.inc
Batch operation callback: Check status of a remote and local po file.
l10n_update_check_projects_local in ./l10n_update.compare.inc
Check and store the status and timestamp of local po files.

File

./l10n_update.translation.inc, line 171
Common API for interface translation.

Code

function l10n_update_source_check_file($source) {
  if (isset($source->files[L10N_UPDATE_LOCAL])) {
    $source_file = $source->files[L10N_UPDATE_LOCAL];
    $directory = $source_file->directory;
    $filename = '/^' . preg_quote($source_file->filename) . '$/';
    if ($files = file_scan_directory($directory, $filename, array(
      'key' => 'name',
      'recurse' => FALSE,
    ))) {
      $file = current($files);
      $source_file->uri = $file->uri;
      $source_file->timestamp = filemtime($file->uri);
      return $source_file;
    }
  }
  return FALSE;
}