class LocaleTranslation

Same name in this branch
  1. main core/modules/locale/src/LocaleTranslation.php \Drupal\locale\LocaleTranslation
Same name and namespace in other branches
  1. 10 core/modules/locale/src/LocaleTranslation.php \Drupal\locale\LocaleTranslation
  2. 10 core/modules/locale/src/Plugin/QueueWorker/LocaleTranslation.php \Drupal\locale\Plugin\QueueWorker\LocaleTranslation
  3. 11.x core/modules/locale/src/LocaleTranslation.php \Drupal\locale\LocaleTranslation
  4. 11.x core/modules/locale/src/Plugin/QueueWorker/LocaleTranslation.php \Drupal\locale\Plugin\QueueWorker\LocaleTranslation
  5. 9 core/modules/locale/src/LocaleTranslation.php \Drupal\locale\LocaleTranslation
  6. 9 core/modules/locale/src/Plugin/QueueWorker/LocaleTranslation.php \Drupal\locale\Plugin\QueueWorker\LocaleTranslation
  7. 8.9.x core/modules/locale/src/LocaleTranslation.php \Drupal\locale\LocaleTranslation
  8. 8.9.x core/modules/locale/src/Plugin/QueueWorker/LocaleTranslation.php \Drupal\locale\Plugin\QueueWorker\LocaleTranslation

Executes interface translation queue tasks.

Attributes

#[QueueWorker(id: 'locale_translation', title: new TranslatableMarkup('Update translations'), cron: [ 'time' => 30, ])]

Hierarchy

Expanded class hierarchy of LocaleTranslation

File

core/modules/locale/src/Plugin/QueueWorker/LocaleTranslation.php, line 17

Namespace

Drupal\locale\Plugin\QueueWorker
View source
class LocaleTranslation extends QueueWorkerBase implements ContainerFactoryPluginInterface {
  
  /**
   * The queue object.
   *
   * @var \Drupal\Core\Queue\QueueInterface
   */
  protected $queue;
  public function __construct(array $configuration, string $plugin_id, array $plugin_definition, protected ModuleHandlerInterface $moduleHandler, QueueInterface $queue, protected readonly CallableResolver $callableResolver) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->queue = $queue;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container->get('module_handler'), $container->get('queue')
      ->get('locale_translation', TRUE), $container->get(CallableResolver::class));
  }
  
  /**
   * {@inheritdoc}
   *
   * The translation update functions executed here are batch operations which
   * are also used in translation update batches. The batch functions may need
   * to be executed multiple times to complete their task, typically this is the
   * translation import function. When a batch function is not finished, a new
   * queue task is created and added to the end of the queue. The batch context
   * data is needed to continue the batch task is stored in the queue with the
   * queue data.
   */
  public function processItem($data) {
    $this->moduleHandler
      ->loadInclude('locale', 'batch.inc');
    [$callable, $args] = $data;
    // We execute batch operation functions here to check, download and import
    // the translation files. Batch functions use a context variable as last
    // argument which is passed by reference. When a batch operation is called
    // for the first time a default batch context is created. When called
    // iterative (usually the batch import function) the batch context is passed
    // through via the queue and is part of the $data.
    $last = count($args) - 1;
    if (!is_array($args[$last]) || !isset($args[$last]['finished'])) {
      $batch_context = [
        'sandbox' => [],
        'results' => [],
        'finished' => 1,
        'message' => '',
      ];
    }
    else {
      $batch_context = $args[$last];
      unset($args[$last]);
    }
    $args = array_merge($args, [
      &$batch_context,
    ]);
    // Call the batch operation function.
    $resolvedCallable = $this->callableResolver
      ->getCallableFromDefinition($callable);
    $resolvedCallable(...$args);
    // If the batch operation is not finished we create a new queue task to
    // continue the task. This is typically the translation import task.
    if ($batch_context['finished'] < 1) {
      unset($batch_context['strings']);
      $this->queue
        ->createItem([
        $callable,
        $args,
      ]);
    }
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AutowiredInstanceTrait::createInstanceAutowired public static function Instantiates a new instance of the implementing class using autowiring.
AutowiredInstanceTrait::getAutowireArguments private static function Resolves arguments for a method using autowiring.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
LocaleTranslation::$queue protected property The queue object.
LocaleTranslation::create public static function Instantiates a new instance of the implementing class using autowiring. Overrides PluginBase::create
LocaleTranslation::processItem public function The translation update functions executed here are batch operations which
are also used in translation update batches. The batch functions may need
to be executed multiple times to complete their task, typically this is the
translation import…
Overrides QueueWorkerInterface::processItem
LocaleTranslation::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
MessengerTrait::$messenger protected property The messenger. 26
MessengerTrait::messenger public function Gets the messenger. 26
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin ID.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin ID of the plugin instance. Overrides PluginInspectionInterface::getPluginId
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.