Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

public function FileTranslator::requestTranslation

@abstract

Submits the translation request and sends it to the translation provider.

During the translation process, Job::getItems() will only return job items that are not already fully translated.

Parameters

\Drupal\tmgmt\JobInterface $job: The job that should be submitted.

Overrides TranslatorPluginInterface::requestTranslation

See also

hook_tmgmt_job_before_request_translation()

hook_tmgmt_job_after_request_translation()

File

translators/tmgmt_file/src/Plugin/tmgmt/Translator/FileTranslator.php, line 34

Class

FileTranslator
File translator.

Namespace

Drupal\tmgmt_file\Plugin\tmgmt\Translator

Code

public function requestTranslation(JobInterface $job) {
  $name = "JobID" . $job
    ->id() . '_' . $job
    ->getSourceLangcode() . '_' . $job
    ->getTargetLangcode();
  $export = \Drupal::service('plugin.manager.tmgmt_file.format')
    ->createInstance($job
    ->getSetting('export_format'), $job
    ->getSetting('format_configuration'));
  $path = $job
    ->getSetting('scheme') . '://tmgmt_file/' . $name . '.' . $job
    ->getSetting('export_format');
  $dirname = dirname($path);
  if (\Drupal::service('file_system')
    ->prepareDirectory($dirname, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
    $file = \Drupal::service('file.repository')
      ->writeData($export
      ->export($job), $path, FileSystemInterface::EXISTS_REPLACE);
    \Drupal::service('file.usage')
      ->add($file, 'tmgmt_file', 'tmgmt_job', $job
      ->id());
    $job
      ->submitted('Exported file can be downloaded <a href="@link" download>here</a>.', array(
      '@link' => \Drupal::service('file_url_generator')
        ->generateAbsoluteString($path),
    ));
  }
  else {
    $job
      ->rejected('Failed to create writable directory @dirname, check file system permissions.', [
      '@dirname' => $dirname,
    ]);
  }
}