function TMGMTTestTranslatorPluginController::requestTranslation in Translation Management Tool 7
@abstract
Submits the translation request and sends it to the translation provider.
Parameters
TMGMTJob $job: The job that should be submitted.
Overrides TMGMTTranslatorPluginControllerInterface::requestTranslation
File
- tests/
tmgmt_test.plugin.translator.inc, line 40 - Cotains the test translator plugin.
Class
- TMGMTTestTranslatorPluginController
- @file Cotains the test translator plugin.
Code
function requestTranslation(TMGMTJob $job) {
// Add a debug message.
$job
->addMessage('Test translator called.', array(), 'debug');
// Do something different based on the action, if defined.
$action = isset($job->settings['action']) ? $job->settings['action'] : '';
switch ($action) {
case 'submit':
$job
->submitted('Test submit.');
break;
case 'reject':
$job
->rejected('This is not supported.');
break;
case 'fail':
// Target not reachable.
$job
->addMessage('Service not reachable.', array(), 'error');
break;
case 'translate':
default:
// The dummy translation prefixes strings with the target language.
$data = array_filter(tmgmt_flatten_data($job
->getData()), '_tmgmt_filter_data');
$tdata = array();
foreach ($data as $key => $value) {
$tdata[$key]['#text'] = $job->target_language . '_' . $value['#text'];
}
$job
->submitted('Test translation created.');
$job
->addTranslatedData(tmgmt_unflatten_data($tdata));
break;
}
}