function locale_translation_source_build

Builds abstract translation source.

Parameters

object $project: Project object.

string $langcode: Language code.

string $filename: File name of translation file. May contain placeholders.

Return value

object Source object:

  • "project": Project name.
  • "name": Project name (inherited from project).
  • "language": Language code.
  • "core": Core version (inherited from project).
  • "version": Project version (inherited from project).
  • "project_type": Project type (inherited from project).
  • "files": Array of file objects containing properties of local and remote translation files.

Other processes can add the following properties:

The "files" array can hold file objects of type: LOCALE_TRANSLATION_LOCAL, LOCALE_TRANSLATION_REMOTE, LOCALE_TRANSLATION_DOWNLOADED, LOCALE_TRANSLATION_IMPORTED and LOCALE_TRANSLATION_CURRENT. Each contains following properties:

  • "type": The object type (LOCALE_TRANSLATION_LOCAL, LOCALE_TRANSLATION_REMOTE, etc. see above).
  • "project": Project name.
  • "langcode": Language code.
  • "version": Project version.
  • "uri": Local or remote file path.
  • "directory": Directory of the local po file.
  • "filename": File name.
  • "timestamp": Timestamp of the file.
  • "keep": TRUE to keep the downloaded file.
2 calls to locale_translation_source_build()
locale_translation_build_sources in drupal/core/modules/locale/locale.translation.inc
Build translation sources.
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.translation.inc, line 233
Common API for interface translation.

Code

function locale_translation_source_build($project, $langcode, $filename = NULL) {

  // Followup issue: http://drupal.org/node/1842380
  // Convert $source object to a TranslatableProject class and use a typed class
  // for $source-file.
  // Create a source object with data of the project object.
  $source = clone $project;
  $source->project = $project->name;
  $source->langcode = $langcode;
  $filename = $filename ? $filename : config('locale.settings')
    ->get('translation.default_filename');

  // If the server_pattern contains a remote file path we will check for a
  // remote file. The local version of this file will only be checked if a
  // translations directory has been defined. If the server_pattern is a local
  // file path we will only check for a file in the local file system.
  $files = array();
  if (_locale_translation_file_is_remote($source->server_pattern)) {
    $files[LOCALE_TRANSLATION_REMOTE] = (object) array(
      'project' => $project->name,
      'langcode' => $langcode,
      'version' => $project->version,
      'type' => LOCALE_TRANSLATION_REMOTE,
      'filename' => locale_translation_build_server_pattern($source, basename($source->server_pattern)),
      'uri' => locale_translation_build_server_pattern($source, $source->server_pattern),
    );
    if (config('locale.settings')
      ->get('translation.path')) {
      $files[LOCALE_TRANSLATION_LOCAL] = (object) array(
        'project' => $project->name,
        'langcode' => $langcode,
        'version' => $project->version,
        'type' => LOCALE_TRANSLATION_LOCAL,
        'filename' => locale_translation_build_server_pattern($source, $filename),
        'directory' => 'translations://',
      );
      $files[LOCALE_TRANSLATION_LOCAL]->uri = $files[LOCALE_TRANSLATION_LOCAL]->directory . $files[LOCALE_TRANSLATION_LOCAL]->filename;
    }
  }
  else {
    $files[LOCALE_TRANSLATION_LOCAL] = (object) array(
      'project' => $project->name,
      'langcode' => $langcode,
      'version' => $project->version,
      'type' => LOCALE_TRANSLATION_LOCAL,
      'filename' => locale_translation_build_server_pattern($source, basename($source->server_pattern)),
      'directory' => locale_translation_build_server_pattern($source, drupal_dirname($source->server_pattern)),
    );
    $files[LOCALE_TRANSLATION_LOCAL]->uri = $files[LOCALE_TRANSLATION_LOCAL]->directory . '/' . $files[LOCALE_TRANSLATION_LOCAL]->filename;
  }
  $source->files = $files;
  return $source;
}