-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtmgmt_zanata.module
128 lines (114 loc) · 3.74 KB
/
tmgmt_zanata.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* @file
* Module file for translation management Zanata module.
*
* For information on Zanata, see http://zanata.org/
*
* Implemented by David Mason [email protected]
*/
/**
* Implements hook_tmgmt_translator_plugin_info().
*/
function tmgmt_zanata_tmgmt_translator_plugin_info() {
return array(
'zanata' => array(
'label' => t('Zanata translator'),
'description' => t('Service to translate strings with Zanata'),
'plugin controller class' => 'TMGMTZanataTranslatorPluginController',
'ui controller class' => 'TMGMTZanataTranslatorUIController',
// FIXME make sure auto create works properly.
'auto create' => TRUE,
'default settings' => array(
'server' => 'http://translate.zanata.org/zanata',
'segmentation' => 'NONE',
'proxy' => array(
'enable' => FALSE,
'server' => '',
'port' => '',
'username' => '',
'password' => '',
),
),
// TODO look at other settings on the hook page.
),
);
}
/**
* Callback used to force re-sending of all items in a job.
*
* This is triggered from the UI checkoutInfo form.
*/
function tmgmt_zanata_resubmit_translations($form, &$form_state) {
$job = $form_state['tmgmt_job'];
$job->getTranslatorController()->resubmitTranslation($job);
}
/**
* Callback used to poll for translations in the UI checkoutInfo form.
*/
function tmgmt_zanata_poll_translations($form, &$form_state) {
$job = $form_state['tmgmt_job'];
$job->getTranslatorController()->getConnector($job)->pollTranslations();
}
/**
* Implements hook_cron().
*
* Cron based callback used to poll for translations
*/
function tmgmt_zanata_cron() {
if (variable_get('poll_translations_during_cron', TRUE)) {
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'tmgmt_job')->propertyCondition('state',
TMGMT_JOB_STATE_ACTIVE)->propertyCondition('translator', 'zanata')->execute();
if (!empty($result['tmgmt_job'])) {
$active_translation_jobs = array_keys($result['tmgmt_job']);
foreach ($active_translation_jobs as $job_id) {
$job = tmgmt_job_load($job_id);
if ($job->getTranslator()->getSetting('transcheck')) {
$job->getTranslatorController()->getConnector($job)->pollTranslations();
}
}
}
}
}
/**
* Implements hook_menu().
*/
function tmgmt_zanata_menu() {
$items = array();
$items['admin/tmgmt/express_checkout'] = array(
'title' => 'TMGMT Express Checkout',
'description' => 'Express checkout for TMGMT jobs',
'page callback' => 'drupal_get_form',
'page arguments' => array('tmgmt_zanata_express_checkout_form'),
// Not sure why there is no access restriction.
'access callback' => TRUE,
// This prevents the form displaying in the main navigation menu.
'menu_name' => 'tmgmt_express_checkout',
'file' => 'tmgmt_zanata.checkout.inc',
);
return $items;
}
/**
* Implements hook_tmgmt_ui_job_checkout_before_alter().
*
* Called when jobs have been created, but before all the individual checkout
* forms. Jobs and redirects can be modified here to change the checkout
* workflow.
*/
function tmgmt_zanata_tmgmt_ui_job_checkout_before_alter(&$redirects, &$jobs) {
// Array of [name => label].
$translators = tmgmt_translator_labels();
// Reset pointer to first element.
reset($translators);
// Save the job ids in the session, for use by the express checkout form.
$job_ids = array();
foreach ($jobs as $job) {
$job_ids[] = $job->tjid;
}
if (!isset($_SESSION['tmgmt_express_checkout'])) {
$_SESSION['tmgmt_express_checkout'] = array();
}
$_SESSION['tmgmt_express_checkout']['job_ids'] = $job_ids;
$redirects[] = 'admin/tmgmt/express_checkout';
}