Builds abstract translation source.
object $project: Project object.
string $langcode: Language code.
string $filename: File name of translation file. May contain placeholders.
object Source object:
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:
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;
}