function tmgmt_local_translators in Translation Management Tool 7
Gets local translator for given language combination.
Parameters
string $source_language: (optional) Source language to limit on.
array $target_languages: (optional) List of target languages to limit to.
Return value
array Array of uid => name translators or empty array if there are no translator users.
4 calls to tmgmt_local_translators()
- TMGMTLocalTestCase::testCapabilitiesAPI in translators/
tmgmt_local/ tmgmt_local.test - TMGMTLocalTranslatorUIController::checkoutSettingsForm in translators/
tmgmt_local/ includes/ tmgmt_local.plugin.ui.inc - Form callback for the checkout settings form.
- tmgmt_local_get_translators_for_tasks in translators/
tmgmt_local/ tmgmt_local.module - Gets translators able to translate all given tasks.
- tmgmt_local_task_form in translators/
tmgmt_local/ includes/ tmgmt_local.pages.inc - Entity API form the local task entity.
File
- translators/
tmgmt_local/ tmgmt_local.module, line 772 - Main module file for the local translation module.
Code
function tmgmt_local_translators($source_language = NULL, array $target_languages = array()) {
$translators =& drupal_static(__FUNCTION__);
$key = $source_language . '_' . implode('_', $target_languages);
if (isset($translators[$key])) {
return $translators[$key];
}
// Get all capabilities keyed by uids for given source language.
$translators_capabilities = array();
foreach (tmgmt_local_capabilities($source_language) as $row) {
$translators_capabilities[$row->uid][] = $row->tmgmt_translation_skills_language_to;
}
// Filter out translator uids who's capabilities are not sufficient for given
// target languages.
$translators_uids = array();
foreach ($translators_capabilities as $uid => $translator_capabilities) {
// In case provided target languages exceed users capabilities exclude.
if (!empty($target_languages) && count(array_diff($target_languages, $translator_capabilities)) > 0) {
continue;
}
$translators_uids[] = $uid;
}
// Finally build the translators list.
$translators[$key] = array();
if (!empty($translators_uids)) {
foreach (user_load_multiple($translators_uids) as $account) {
$translators[$key][$account->uid] = entity_label('user', $account);
}
}
return $translators[$key];
}