\Drupal\Core\StringTranslation\TranslationManager is what we're using to replace t().
But the method isn't on any interface.

This issue should also fix the typehints anywhere we inject this.

CommentFileSizeAuthor
#3 translate_interface-2049709-1.patch3.02 KBplopesc
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plopesc’s picture

Hello,

I glimpsed this issue and found that TranslatorInterface is implemented by 3 classes:

  • Drupal\Core\StringTranslation\TranslationManager
  • Drupal\Core\StringTranslation\Translator\StaticTranslation
  • Drupal\locale\LocaleTranslation

But only Drupal\Core\StringTranslation\TranslationManager class provides translate method. Then, I don't know exactly how should we face with this issue, because if this method is added to the interface, all these classes should implement this method.

Maybe we could extend TranslatorInterface and implement this new interface only in TranslationManager class.

What do you think?

Regards

tim.plunkett’s picture

#2018411-8: Figure out a nice DX when working with injected translation proposes a new interface. We can borrow part of that patch here.

plopesc’s picture

Status: Active » Needs review
FileSize
3.02 KB

Including patch based on #2049709-8: TranslationManager::translate() should be on an interface, just removing the __invoke() call, which I think is not covered in this issue.

However, this patch does not address the issue title given that this method is not included in TranslatorInterface.
What do you think?

Regards.

tim.plunkett’s picture

Title: TranslationManager::translate() should be on TranslatorInterface » TranslationManager::translate() should be on an interface

:)

dawehner’s picture

I try to figure out why we both need Translator and TranslationInterface. Is it really impossible to combine this two methods into one?

ParisLiakos’s picture

well TranslationManager is actually a translator manager class that "holds" many translators and it can act as a translator by having its own getStringTranslation method, in where it loops through its translators till it retrieves a translation.
Almost same pattern with PathProcessorManager.
(Maybe the naming is wrong all along and should be named TranslatorManager?)

We could add this method to TranslatorInterface, but then we would need a base/abastract class to hold the logic instead of it being only in the manager class.
BUT I think having a TranslationInterface is better, since it allows a totally different translation system (with or without translators). You can think of Translators being an implementation detail of core's string translation. A string translation itself only needs to have the translate method.

If the fact that TranslationManager implementing the TranslatorInterface is confusing, we can remove it and just make it implement TranslationInterface, not both, but we should keep translate() method out of translators

ParisLiakos’s picture

Issue tags: +D8MI

If the fact that TranslationManager implementing the TranslatorInterface is confusing, we can remove it and just make it implement TranslationInterface, not both

this can be addressed in seperate issue so imo is rtbc. Tagging though for more opinions

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

well, the sooner we get this in, the better

tim.plunkett’s picture

Issue tags: +Quick fix

+1. Misusage of TranslationManager and TranslatorInterface are going in all over, and this also blocks a proper resolution on #2059245: Add a FormBase class containing useful methods

tim.plunkett’s picture

#3: translate_interface-2049709-1.patch queued for re-testing.

tim.plunkett’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3e83934 and pushed to 8.x. Thanks!

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