-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Improve handling of non-string messages in MessageCatalogue
#50252
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
[Translation] Improve handling of non-string messages in MessageCatalogue
#50252
Conversation
rob006
commented
May 6, 2023
Q | A |
---|---|
Branch? | 5.4 |
Bug fix? | yes |
New feature? | no |
Deprecations? | no |
Tickets | Fix #49894 |
License | MIT |
Doc PR | - |
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
Hey! Thanks for your PR. You are targeting branch "6.3" but it seems your PR description refers to branch "5.4". Cheers! Carsonbot |
2f27024
to
c3143c2
Compare
unset($this->messages[$domain][$id]); | ||
} else { | ||
unset($this->messages[$altDomain][$id]); | ||
$this->messages[$domain][$id] = (string) $message; |
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.
But the (string) $message
cast will throw an exception if for objects/resources that can't be converted into strings. Maybe it's what we want (to fail loudly so you can catch these errors) but I just wanted to mention it. Thanks.
Adding the validation in the MessageCatalogue constructor will have a performance impact in prod for 2 reasons:
To me, it would be much better to leave MessageCatalogue as is (except adding more precise phpdoc describing the accepted array as being |
How about removing this validation from constructor and leaving it only in I could move validation to loaders, but it will be duplicated at least 3 times, and |
Having the validation in loaders might allow providing better error messages (as they would be able to tell you which resources is being loaded that contains an error). And not all loaders will have the same validation (for instance, Xliff will not allow setting null values as all values are strings in XML) Side note, I don't think the low-level MessageCatalogue object should silently skip values. |
Alternative PR: #50315 |
Closing in favor of #50315 |
…r` (rob006) This PR was merged into the 5.4 branch. Discussion ---------- [Translation] Fix handling of null messages in `ArrayLoader` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #49894 | License | MIT | Doc PR | - Replaces #50252 Commits ------- 4be2036 [Translation] Fix handling of null messages in `ArrayLoader`