Last active
August 11, 2022 16:40
-
-
Save ozin7/64931d66308c0b6b80f994f7f6200e3e to your computer and use it in GitHub Desktop.
Drupal 9: String translation in a Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\gurei\Service; | |
use Drupal\Core\StringTranslation\StringTranslationTrait; | |
use Drupal\Core\StringTranslation\TranslationInterface; | |
/** | |
* Class CompanyService. | |
*/ | |
class CompanyService { | |
use StringTranslationTrait; | |
/** | |
* CompanyService constructor. | |
*/ | |
public function __construct(private TranslationInterface $stringTranslation) {} | |
public function getMessage() { | |
return $this->t('Welcome home'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
gurei.company_manager: | |
class: Drupal\gurei\Service\CompanyService | |
arguments: | |
- '@string_translation' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment