function locale_translation_source_check_file

Check 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 LOCALE_TRANSLATION_DEFAULT_FILENAME. Per project this value can be overridden using the server_pattern directive in the module's .info file or by using hook_locale_translation_projects_alter().

Parameters

stdClass $source: Translation source object. @see locale_translation_source_build()

Return value

stdClass File object (filename, basename, name) updated with data of the po file. On success the files property of the source object is updated. files['local']:

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

FALSE if the file is not found.

2 calls to locale_translation_source_check_file()
locale_translation_batch_status_fetch_local in drupal/core/modules/locale/locale.batch.inc
Batch operation callback: Check the availability of local po files.
locale_translation_check_projects_local in drupal/core/modules/locale/locale.compare.inc
Check and store the status and timestamp of local po files.

File

drupal/core/modules/locale/locale.compare.inc, line 416
The API for comparing project translation status with available translation.

Code

function locale_translation_source_check_file(&$source) {
  if (isset($source->files['local'])) {
    $directory = $source->files['local']->directory;
    $filename = '/' . preg_quote($source->files['local']->filename) . '$/';

    // If the directory contains a stream wrapper, it is converted to a real
    // path. This is required for file_scan_directory() which can not handle
    // stream wrappers.
    if ($scheme = file_uri_scheme($directory)) {
      $directory = str_replace($scheme . '://', drupal_realpath($scheme . '://'), $directory);
    }
    if ($files = file_scan_directory($directory, $filename, array(
      'key' => 'name',
    ))) {
      $file = current($files);
      $source->files['local']->uri = $file->uri;
      $source->files['local']->timestamp = filemtime($file->uri);
      return $file;
    }
  }
  return FALSE;
}