I perceive Drupal 8 ControllerBase implements StringTranslationTrait so we are able to use $this->t() in Controller class. However I discovered in Drupal 8 examples code, they setStringTranslation to make use of t() perform. Right here is Drupal Development Service code.
public static perform create(ContainerInterface $container) { $controller = new static( $container->get('database') ); $controller->setStringTranslation($container->get('string_translation')); return $controller; }
Drupal Development hyperlink for his or her module. https://git.drupalcode.org/mission/examples/blob/8.x-1.x/tablesort_example/src/Controller/TableSortExampleController.php
My query is why setStringTranslation when you possibly can simply use t() perform in Drupal Development Service controller.