Problem/Motivation

The t() documentation says:

When possible, use the \Drupal\Core\StringTranslation\StringTranslationTrait $this->t()

The documentation for the Drupal\Core\Render\Element is using $this->t in an inconsistent way.

There are places where t() is used. In other places $this->t() is used.

Also there are are some strings that should be translatable and they are not wrapped into t().

Proposed resolution

Replace all the t() with $this->t() in the Drupal\Core\Render\Element.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dagmar created an issue. See original summary.

dagmar’s picture

Status: Active » Needs review
FileSize
15.77 KB

Here is the patch.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! I think this patch is a good idea.

It needs an update though -- in several places, you did

$this->('string')

instead of

$this->t('string')

In other words, the "t" in the t() method call got left out by mistake. Whoops!

I found several places where this occurred, but other than that the patch looks great:

  1. +++ b/core/lib/Drupal/Core/Render/Element/Color.php
    @@ -16,7 +16,7 @@
    + *   '#title' => $this->('Color'),
    

    missing t

  2. +++ b/core/lib/Drupal/Core/Render/Element/Container.php
    @@ -15,7 +15,7 @@
    + *   '#title' => $this->('Need Special Accommodations?'),
    

    same here, missing t

  3. +++ b/core/lib/Drupal/Core/Render/Element/Fieldset.php
    @@ -9,12 +9,12 @@
    + *   '#title' => $this->('Author'),
    

    missing t

  4. +++ b/core/lib/Drupal/Core/Render/Element/Tableselect.php
    @@ -118,28 +118,28 @@ public static function valueCallback(&$element, $input, FormStateInterface $form
    +   *         'title' => $this->('How to Learn Drupal'),
    +   *         'content_type' => $this->('Article'),
    

    both of these are missing the t

  5. +++ b/core/lib/Drupal/Core/Render/Element/Tableselect.php
    @@ -118,28 +118,28 @@ public static function valueCallback(&$element, $input, FormStateInterface $form
    +   *         'title' => $this->('Privacy Policy'),
    +   *         'content_type' => $this->('Page'),
    

    more missing t

  6. +++ b/core/lib/Drupal/Core/Render/Element/VerticalTabs.php
    @@ -24,24 +24,24 @@
    + *   '#title' => $this->('Author'),
    

    missing t

dagmar’s picture

Status: Needs work » Needs review
FileSize
15.78 KB
2.95 KB

Sorry! I did a bad search & replace. Here is the new patch.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 72cca02 and pushed to 8.1.x and 8.2.x. Thanks!

I committed this to 8.1.x as well because it is a docs fix only.

  • alexpott committed 6b26b0c on 8.2.x
    Issue #2709411 by dagmar, jhodgdon: t() is used in an inconsistent way...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.