Hello,

The t() function is still present in Drupal 8, as it was in Drupal 7. I suggest to replace t() function with $this->t().

This means that in most Drupal 8 object-oriented code (controllers, listeners, plugins, forms etc.), instead of using the global t() function, you should instead use dependency injection.

If there is no suitable base class for your task with a t() method, you can use the StringTranslationTrait to get t() and formatPlural() methods.

Thanks,
Nitin

Comments

Nitin Shirole created an issue. See original summary.

nitin shirole’s picture

Status: Active » Needs review
StatusFileSize
new19.86 KB

Status: Needs review » Needs work

The last submitted patch, 2: pathauto-2807099-2.patch, failed testing.

The last submitted patch, 2: pathauto-2807099-2.patch, failed testing.

The last submitted patch, 2: pathauto-2807099-2.patch, failed testing.

nitin shirole’s picture

Status: Needs work » Needs review
StatusFileSize
new11.31 KB

  • Berdir committed 369d3fa on 8.x-1.x authored by Nitin Shirole
    Issue #2807099 by Nitin Shirole: Use DI for translatable strings instead...
berdir’s picture

Status: Needs review » Fixed

Thanks.

Status: Fixed » Closed (fixed)

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