TMGMT now supports adding arbitrary files to translation jobs.
Files are extracted from file reference fields that are set to translatable and the file must have one of the enabled mime types on the TMGMT settings page.
This feature must be explicitly supported by the used translation service provider. Once at least one provider opts-in to that feature by adding files = TRUE to their annotation, the mime type settings and the file count statistic become visible.
Two new API methods on the Data service are provided to support provider implementations in using these features, getTranslatableFiles() and createFileTranslation, see the TestTranslator integration:
/** @var \Drupal\tmgmt\Data $data_service */
$data_service = \Drupal::service('tmgmt.data');
foreach ($data_service->getTranslatableFiles($job_item->getData()) as $key => $source_file) {
$source_uri = $source_file->getFileUri();
$source_content = file_get_contents($source_uri);
if ($target_langcode != $remote_target_langcode) {
$translation_content = $target_langcode . '(' . $remote_target_langcode . '): ' . $source_content;
}
else {
$translation_content = $target_langcode . ': ' . $source_content;
}
$translation_file = $data_service->createFileTranslation($source_file, $target_langcode, $translation_content);
$tdata[$key]['#file'] = $translation_file->id();
}
A real implementation will send the file content to an API and then save a received translation at a later stage.
Supported mime types are currently not validated, it is technically possible enable anything, but whether or not they can actually be translated depends entirely on the used translation service provider and this feature should be configured according to their documentation and provided information.