-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Contracts] add TranslatableInterface #38330
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Contracts] add TranslatableInterface #38330
Conversation
fc04851
to
059cc32
Compare
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.
Better!
3697bee
to
b5df1f5
Compare
*/ | ||
public function trans($message, array $arguments = [], string $domain = null, string $locale = null, int $count = null): string | ||
public function trans($message, $arguments = [], string $domain = null, string $locale = null, int $count = null): 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.
The new semantics of the $arguments
parameter is not covered by a test, is it? I also wonder if this change is really necessary. I find the error message rather confusing that a developer gets when passing an array of arguments to the trans
filter (which can be an honest C&P mistake).
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.
Test case added as {{ t("Hello")|trans("fr") }}
Not doing this polymorphism means that ppl would be forced to always write
{{ translateble|trans(locale=fr) }}
instead of {{ translateble|trans(fr) }}
which the current changes allows.
If the issue is the error message, we could improve it. Suggestions welcome :)
b5df1f5
to
9224f7a
Compare
{ | ||
if (!class_exists(Translatable::class)) { |
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.
it could be an anonymous data object, for general compatibility
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.
it could but I doubt this would provide many benefits. The dependency on the component is quite a loose one for someone using the extension.
Thank you @nicolas-grekas. |
An alternative to #38328:
TranslatableInterface
is added to symfony/contracts;Translatable
, still in the component, implements it (and is not final as it makes no sense for a value-object)t()
function is kept in the component - it doesn't fit in the contracts IMHO;Translatable::trans()
is not static anymore;t()
function moved in theSymfony\Component\Translation
namespace (for reference, thes()
function from String is also namespaced.);