- Notifications
You must be signed in to change notification settings - Fork11.7k
Enhancing Laravel: Introducing Enum Translation for a Seamless Developer Experience#49464
-
Hey Laravel Core Team, I've got a suggestion that could level up the developer experience with the framework: how about adding a feature to translate enums? Ever thought about it? Enums are super handy, but things get a bit tricky when we're dealing with different languages. Having a function to translate enums directly would be a game-changer! Just imagine being able to set translations for each enum value in language files. It would make managing multilingual apps a breeze without making the code overly complicated. It would be awesome if you could consider this idea for upcoming Laravel versions. It would make developers' lives so much easier and amp up the framework's adaptability. I'm totally up for a more detailed discussion if you're interested! Thanks for everything you do to evolve Laravel. I can work on it if you think it's a good idea. Thanks |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 5 comments 1 reply
-
Something like this |
BetaWas this translation helpful?Give feedback.
All reactions
-
I don't have any answers, so I created a package, but it would be better directly in the chore. Of course, I can take care of it, with the documentation etc. |
BetaWas this translation helpful?Give feedback.
All reactions
-
this is already easy enough to do in userland: enum Test:string{caseFOO ='foo';caseBAR ='bar';caseBAZ ='baz';publicfunctiondisplay():string {returnmatch ($this) {self::FOO =>__('enums/foo'),self::BAR =>__('enums/bar'),self::BAZ =>__('enums/baz'), }; } |
BetaWas this translation helpful?Give feedback.
All reactions
-
I think it's not really the same. Of course, it's possible to do that in many ways... I find my solution quite interesting, at least for a package, and in the worst case... I use it myself. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I don't believe, enum valuesshould be used for this (directly). There's also |
BetaWas this translation helpful?Give feedback.
All reactions
-
I have created a package that manages Enum translation in an elegant way |
BetaWas this translation helpful?Give feedback.