class LocalTranslator in Translation Management Tool 8
Drupal user provider.
Plugin annotation
@TranslatorPlugin(
id = "local",
label = @Translation("Drupal user"),
description = @Translation("Allows local users to process translation jobs."),
ui = "\Drupal\tmgmt_local\LocalTranslatorUi",
default_settings = {},
map_remote_languages = FALSE
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\tmgmt\TranslatorPluginBase implements TranslatorPluginInterface
- class \Drupal\tmgmt_local\Plugin\tmgmt\Translator\LocalTranslator implements ContinuousTranslatorInterface
- class \Drupal\tmgmt\TranslatorPluginBase implements TranslatorPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of LocalTranslator
File
- translators/
tmgmt_local/ src/ Plugin/ tmgmt/ Translator/ LocalTranslator.php, line 26
Namespace
Drupal\tmgmt_local\Plugin\tmgmt\TranslatorView source
class LocalTranslator extends TranslatorPluginBase implements ContinuousTranslatorInterface {
protected $language_pairs = array();
/**
* {@inheritdoc}
*/
public function requestTranslation(JobInterface $job) {
$items = $job
->getItems();
$this
->requestJobItemsTranslation($items);
// The translation job has been successfully submitted.
$job
->submitted();
}
/**
* {@inheritdoc}
*/
public function requestJobItemsTranslation(array $job_items) {
/** @var \Drupal\tmgmt\Entity\Job $job */
$job = reset($job_items)
->getJob();
$tuid = $job
->getSetting('translator');
// Create local task for this job.
/** @var \Drupal\tmgmt_local\LocalTaskInterface $local_task */
$local_task = LocalTask::create(array(
'uid' => $job
->getOwnerId(),
'tuid' => $tuid,
'tjid' => $job
->id(),
'title' => $job
->label(),
));
// If we have translator then switch to pending state.
if ($tuid) {
$local_task->status = LocalTaskInterface::STATUS_PENDING;
}
$local_task
->save();
// Create task items.
foreach ($job_items as $item) {
$local_task
->addTaskItem($item);
$item
->active();
}
}
/**
* {@inheritdoc}
*/
public function getSupportedTargetLanguages(TranslatorInterface $translator, $source_language) {
$languages = tmgmt_local_supported_target_languages($source_language);
if (\Drupal::config('tmgmt_local.settings')
->get('allow_all')) {
$languages += parent::getSupportedTargetLanguages($translator, $source_language);
}
return $languages;
}
/**
* {@inheritdoc}
*/
public function getSupportedLanguagePairs(TranslatorInterface $translator) {
if (!empty($this->language_pairs)) {
return $this->language_pairs;
}
$roles = user_roles(TRUE, 'provide translation services');
$query = \Drupal::database()
->select('field_data_tmgmt_translation_skills', 'ts');
$query
->join('users', 'u', 'u.uid = ts.entity_id AND u.status = 1');
$query
->addField('ts', 'tmgmt_translation_skills_language_from', 'source_language');
$query
->addField('ts', 'tmgmt_translation_skills_language_to', 'target_language');
$query
->condition('ts.deleted', 0);
$query
->condition('ts.entity_type', 'user');
if (!in_array(AccountInterface::AUTHENTICATED_ROLE, array_keys($roles))) {
$query
->join('users_roles', 'ur', 'ur.uid = u.uid AND ur.rid');
$or_conditions = (new Condition('OR'))
->condition('ur.rid', array_keys($roles), 'IN')
->condition('u.uid', 1);
$query
->condition($or_conditions);
}
foreach ($query
->execute()
->fetchAll() as $item) {
$this->language_pairs[] = array(
'source_language' => $item->source_language,
'target_language' => $item->target_language,
);
}
return $this->language_pairs;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
LocalTranslator:: |
protected | property | ||
LocalTranslator:: |
public | function |
Default implementation that gets target languages for each remote language.
This approach is ineffective and therefore it is advised that a plugin
should provide own implementation. Overrides TranslatorPluginBase:: |
|
LocalTranslator:: |
public | function |
Returns all available target languages that are supported by this service
when given a source language. Overrides TranslatorPluginBase:: |
|
LocalTranslator:: |
public | function |
Requests the translation of a JobItem. Overrides ContinuousTranslatorInterface:: |
|
LocalTranslator:: |
public | function |
@abstract Overrides TranslatorPluginInterface:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TranslatorPluginBase:: |
protected | property | Characters that indicate the end of an escaped string. | 1 |
TranslatorPluginBase:: |
protected | property | Characters that indicate the beginning of an escaped string. | 1 |
TranslatorPluginBase:: |
public | function |
Aborts a translation job. Overrides TranslatorPluginInterface:: |
|
TranslatorPluginBase:: |
public | function |
Accept a single data item. Overrides TranslatorPluginInterface:: |
|
TranslatorPluginBase:: |
public | function |
Checks whether a translator is available. Overrides TranslatorPluginInterface:: |
1 |
TranslatorPluginBase:: |
public | function |
Check whether this service can handle a particular translation job. Overrides TranslatorPluginInterface:: |
2 |
TranslatorPluginBase:: |
public | function |
Defines default settings. Overrides TranslatorPluginInterface:: |
1 |
TranslatorPluginBase:: |
public | function |
Returns the escaped #text of a data item. Overrides TranslatorPluginInterface:: |
|
TranslatorPluginBase:: |
public | function |
Specifies default mappings for local to remote language codes. Overrides TranslatorPluginInterface:: |
1 |
TranslatorPluginBase:: |
protected | function | Returns the escaped string. | |
TranslatorPluginBase:: |
public | function |
Gets all supported languages of the translator. Overrides TranslatorPluginInterface:: |
|
TranslatorPluginBase:: |
public | function |
Returns if the translator has any settings for the passed job. Overrides TranslatorPluginInterface:: |
2 |
TranslatorPluginBase:: |
public | function |
Removes escape patterns from an escaped text. Overrides TranslatorPluginInterface:: |