Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Mailer][TwigBridge] Add support for translatable subject#59967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
norkunas commentedMar 13, 2025
Q | A |
---|---|
Branch? | 7.3 |
Bug fix? | no |
New feature? | yes |
Deprecations? | no |
Issues | Fix#54203 |
License | MIT |
aefcbb8
toa9b69b4
Compare@stof can you review this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Instead of this, which adds cross-cutting concerns to the base class (= combinatory explosion), what about allowing Email objects to implement TranslatableInterface?
So the trans method would act as a subject getter? |
nicolas-grekas commentedMar 17, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hum, maybe not, I thing I had something else in mind ("static" instead of "string" as return type): interface TranslatableInterface{publicfunctiontrans(TranslatorInterface$translator, ?string$locale =null):static;} 🤔 |
For me it doesn't matter if I'd need to call trans or translatableSubject, still it will need to be stored as it's done now, no? |
What about having the existing subject accept a stringable object? Then, in the listener (or a translation specific one), check for an instance of TranslatableMessage and translate? |
If argument widening is not a BC break then sure |
a9b69b4
tofb59ac0
Compare
Done. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Mailer/Tests/EventListener/MessageListenerTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
fb59ac0
to97eb49b
CompareThank you@norkunas. |
fcdc0cf
intosymfony:7.3Uh oh!
There was an error while loading.Please reload this page.
@@ -58,9 +58,9 @@ class Email extends Message | |||
/** | |||
* @return $this | |||
*/ | |||
public function subject(string $subject): static | |||
public function subject(string|\Stringable $subject): static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This may be a breaking change for apps that extend this class and override this method (https://3v4l.org/uuJj9)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Supporting a TranslatableInterface is absolutely not the same than supporting Stringable. There is no requirement for TranslatableInterface to be Stringable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yeah, my idea was off the cuff. Needs to be thought out more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
btw, even for the core TranslatableMessage (that is stringable), casting it to string does not translate it. It returns the translation key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Right, I thought that'd be fine as that's the behavior of using keys that don't have a translation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
My thinking was to allow the subject to beany stringable object allowing a listener to intercept. If none does, it would just be cast to a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Adding support for Stringable and then doing weird magic to support TranslatableMessage while the changelog says it adds support for translatable subject (which would be understood as being the interface by many people) looks wrong to me (and limiting as there are valid use cases for other implementations of TranslatableInterface)
This does not make sense. The return value of |
@norkunas, without this pr, you could achieve subject translation in the template I think? {%do email.setSubject(...translate...) %} |
This looks like a workaround :) |
…ble objects" (kbond)This PR was squashed before being merged into the 7.3 branch.Discussion----------[Mailer][TwigBridge] Revert "Add support for translatable objects"| Q | A| ------------- | ---| Branch? | 7.3| Bug fix? | no| New feature? | no| Deprecations? | no| Issues | Reverts#60047 | License | MIT#59967 introduced a BC break so we need to revert and find another solution.Commits-------41cc1d6 code reviewf638a6a Revert "[Mailer][TwigBridge] Add support for translatable subject"e51607b Revert "fix compatibility with TwigBridge < 7.3"