Skip to content

[9.x] Stringables for Translator class #45874

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

Merged
merged 2 commits into from
Jan 31, 2023

Conversation

peterfox
Copy link
Contributor

@peterfox peterfox commented Jan 30, 2023

Changes

  • Adds a stringable method to the Translator class
  • Adds the ReflectsClosures trait to the Translator class
  • Adds a mechanism to process objects passed into the translator get method to return the object into a string.
  • Adds a test to demo the use of altering how a Carbon datetime object could be altered from its default string form.

Why

This behaves precisely to how Stringables work with the Blade compiler. The use case for this is that sometimes it's a pain having to format everything before passing it to the get method. Instead, the translator can handle the values as objects and convert them to strings.

Notes

This won't cause conflicts or break anything, as it's all additional code. That said, there is no Facade for the Translator currently. This would be hard to document as a feature as the more visible method would be:

trans()->stringable(fn(Carbon $carbon) => $carbon->format('Y-m-d'));

@peterfox peterfox changed the title [Features] Stringables for Translator class [9.x] Stringables for Translator class Jan 30, 2023
@taylorotwell taylorotwell merged commit fc299c0 into laravel:9.x Jan 31, 2023
@peterfox peterfox deleted the feature/translation-stringables branch January 31, 2023 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants