public function SmartlingTranslator::requestTranslation in TMGMT Translator Smartling 8.2
Same name and namespace in other branches
- 8.4 src/Plugin/tmgmt/Translator/SmartlingTranslator.php \Drupal\tmgmt_smartling\Plugin\tmgmt\Translator\SmartlingTranslator::requestTranslation()
- 8 src/Plugin/tmgmt/Translator/SmartlingTranslator.php \Drupal\tmgmt_smartling\Plugin\tmgmt\Translator\SmartlingTranslator::requestTranslation()
- 8.3 src/Plugin/tmgmt/Translator/SmartlingTranslator.php \Drupal\tmgmt_smartling\Plugin\tmgmt\Translator\SmartlingTranslator::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()
1 call to SmartlingTranslator::requestTranslation()
- SmartlingTranslator::requestJobItemsTranslation in src/
Plugin/ tmgmt/ Translator/ SmartlingTranslator.php - Requests the translation of a JobItem.
File
- src/
Plugin/ tmgmt/ Translator/ SmartlingTranslator.php, line 154 - Contains \Drupal\tmgmt_smartling\Plugin\tmgmt\Translator\SmartlingTranslator.
Class
- SmartlingTranslator
- Smartling translator plugin.
Namespace
Drupal\tmgmt_smartling\Plugin\tmgmt\TranslatorCode
public function requestTranslation(JobInterface $job) {
$name = $this
->getFileName($job);
$export_format = pathinfo($name, PATHINFO_EXTENSION);
$export = $this->formatPluginsManager
->createInstance($export_format);
$path = $job
->getSetting('scheme') . '://tmgmt_sources/' . $name;
$dirname = dirname($path);
if (file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) {
$data = $export
->export($job);
$file = file_save_data($data, $path, FILE_EXISTS_REPLACE);
$this->fileUsage
->add($file, 'tmgmt_smartling', 'tmgmt_job', $job
->id());
$job
->submitted('Exported file can be downloaded <a href="@link">here</a>.', array(
'@link' => file_create_url($path),
));
}
else {
$e = new \Exception('It is not possible to create a directory ' . $dirname);
watchdog_exception('tmgmt_smartling', $e);
$job
->rejected('Job has been rejected with following error: @error', [
'@error' => $e
->getMessage(),
], 'error');
}
try {
$api = $this
->getApi($job
->getTranslator());
$upload_params = new UploadFileParameters();
$upload_params
->setAuthorized(0);
$upload_params
->set('smartling.placeholder_format_custom', $job
->getSetting('custom_regexp_placeholder'));
if ($job
->getSetting('auto_authorize_locales')) {
$upload_params
->setLocalesToApprove($job
->getRemoteTargetLanguage());
}
if ($job
->getTranslator()
->getSetting('callback_url_use')) {
$upload_params
->set('callbackUrl', $this
->getCallbackUrl($job));
}
$api
->uploadFile(\Drupal::service('file_system')
->realpath($file
->getFileUri()), $file
->getFilename(), $export_format === 'xlf' ? 'xliff' : $export_format, $upload_params);
$this->eventDispatcher
->dispatch(RequestTranslationEvent::REQUEST_TRANSLATION_EVENT, new RequestTranslationEvent($job));
Drupal::logger('tmgmt_smartling')
->info(t('File uploaded. Job id: @job_id, file name: @name.', [
'@name' => $job
->getTranslatorPlugin()
->getFileName($job),
'@job_id' => $job
->id(),
]));
} catch (\Exception $e) {
watchdog_exception('tmgmt_smartling', $e);
$job
->rejected('Job has been rejected with following error: @error uploading @file', array(
'@error' => $e
->getMessage(),
'@file' => $file
->getFileUri(),
), 'error');
}
// @todo disallow to submit translation to unsupported language.
}