Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Translation.php

function Translation::__construct

Constructs a new class instance.

Parses values passed into this class through the t() function in Drupal and handles an optional context for the string.

Parameters

array $values: Possible array keys:

  • value (required): the string that is to be translated.
  • arguments (optional): an array with placeholder replacements, keyed by placeholder.
  • context (optional): a string that describes the context of "value";

File

core/lib/Drupal/Core/Annotation/Translation.php, line 75

Class

Translation
Defines a translatable annotation object.

Namespace

Drupal\Core\Annotation

Code

public function __construct(array $values) {
    $string = $values['value'];
    $arguments = $values['arguments'] ?? [];
    $options = [];
    if (!empty($values['context'])) {
        $options = [
            'context' => $values['context'],
        ];
    }
    $this->translation = new TranslatableMarkup($string, $arguments, $options);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal