function l10n_update_source_build in Localization update 7.2
Same name and namespace in other branches
- 6 l10n_update.check.inc \l10n_update_source_build()
- 7 l10n_update.check.inc \l10n_update_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:
- "type": Most recent translation source found. L10N_UPDATE_REMOTE and L10N_UPDATE_LOCAL indicate available new translations, L10N_UPDATE_CURRENT indicate that the current translation is them most recent. "type" sorresponds with a key of the "files" array.
- "timestamp": The creation time of the "type" translation (file).
- "last_checked": The time when the "type" translation was last checked.
The "files" array can hold file objects of type: L10N_UPDATE_LOCAL, L10N_UPDATE_REMOTE and L10N_UPDATE_CURRENT. Each contains following properties:
- "type": The object type (L10N_UPDATE_LOCAL, L10N_UPDATE_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.
3 calls to l10n_update_source_build()
- l10n_update_build_sources in ./
l10n_update.translation.inc - Build translation sources.
- l10n_update_check_projects_local in ./
l10n_update.compare.inc - Check and store the status and timestamp of local po files.
- l10n_update_status_save in ./
l10n_update.module - Saves the status of translation sources in static cache.
File
- ./
l10n_update.translation.inc, line 228 - Common API for interface translation.
Code
function l10n_update_source_build($project, $langcode, $filename = NULL) {
// Create a source object with data of the project object.
$source = clone $project;
$source->project = $project->name;
$source->langcode = $langcode;
$source->type = '';
$source->timestamp = 0;
$source->last_checked = 0;
$filename = $filename ? $filename : variable_get('l10n_update_default_filename', L10N_UPDATE_DEFAULT_FILE_NAME);
// 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 (_l10n_update_file_is_remote($source->server_pattern)) {
$files[L10N_UPDATE_REMOTE] = (object) array(
'project' => $project->name,
'langcode' => $langcode,
'version' => $project->version,
'type' => L10N_UPDATE_REMOTE,
'filename' => l10n_update_build_server_pattern($source, basename($source->server_pattern)),
'uri' => l10n_update_build_server_pattern($source, $source->server_pattern),
);
$files[L10N_UPDATE_LOCAL] = (object) array(
'project' => $project->name,
'langcode' => $langcode,
'version' => $project->version,
'type' => L10N_UPDATE_LOCAL,
'filename' => l10n_update_build_server_pattern($source, $filename),
'directory' => 'translations://',
);
$files[L10N_UPDATE_LOCAL]->uri = $files[L10N_UPDATE_LOCAL]->directory . $files[L10N_UPDATE_LOCAL]->filename;
}
else {
$files[L10N_UPDATE_LOCAL] = (object) array(
'project' => $project->name,
'langcode' => $langcode,
'version' => $project->version,
'type' => L10N_UPDATE_LOCAL,
'filename' => l10n_update_build_server_pattern($source, basename($source->server_pattern)),
'directory' => l10n_update_build_server_pattern($source, drupal_dirname($source->server_pattern)),
);
$files[L10N_UPDATE_LOCAL]->uri = $files[L10N_UPDATE_LOCAL]->directory . '/' . $files[L10N_UPDATE_LOCAL]->filename;
}
$source->files = $files;
// If this project+language is already translated, we add its status and
// update the current translation timestamp and last_updated time. If the
// project+language is not translated before, create a new record.
$history = l10n_update_get_file_history();
if (isset($history[$project->name][$langcode]) && $history[$project->name][$langcode]->timestamp) {
$source->files[L10N_UPDATE_CURRENT] = $history[$project->name][$langcode];
$source->type = L10N_UPDATE_CURRENT;
$source->timestamp = $history[$project->name][$langcode]->timestamp;
$source->last_checked = $history[$project->name][$langcode]->last_checked;
}
else {
l10n_update_update_file_history($source);
}
return $source;
}