function locale_translation_source_check_file

locale_translation_source_check_file($source)

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-%version.%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_locale_translation_projects_alter().

Parameters

object $source: Translation source object.

Return value

object 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

locale_translation_source_build()

File

core/modules/locale/locale.translation.inc, line 170
Common API for interface translation.

Code

function locale_translation_source_check_file($source) {
  if (isset($source->files[LOCALE_TRANSLATION_LOCAL])) {
    $source_file = $source->files[LOCALE_TRANSLATION_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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!locale!locale.translation.inc/function/locale_translation_source_check_file/8.1.x