REGE Posted January 25 Share Posted January 25 (edited) I wrote a sample controller class for my module: <?php namespace MyModule\Controller; use PrestaShopBundle\Translation\Translator; final class CustomModuleController { /** @var Translator */ private Translator $translator; public function __construct(Translator $translator) { $this->translator = $translator; } public function foo() { $this->text = $this->translator->trans('My text to translate', [], 'Modules.Mymodule.Custommoduleclass'); } } I would like to translate it. Everything seems fine, but the text to be translated does not appear in BackOffice->International->Translations. However, the translations from the main module file mymodule.php are all there. Am I doing something wrong? How to translate texts from the module controller? Edited February 14 by REGE [SOLVED] (see edit history) Link to comment Share on other sites More sharing options...
REGE Posted February 14 Author Share Posted February 14 I found a solution. I replaced Translator with TranslatorInterface and it started working. <?php namespace MyModule\Controller; use Symfony\Contracts\Translation\TranslatorInterface; final class CustomModuleController { /** @var TranslatorInterface */ private TranslatorInterface $translator; public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } public function foo() { $this->text = $this->translator->trans('My text to translate', [], 'Modules.Mymodule.Custommoduleclass'); } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now