Enhancing Laravel: Introducing Enum Translation for a Seamless Developer Experience #49464
Replies: 4 comments 1 reply
-
Something like this |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
this is already easy enough to do in userland: enum Test: string
{
case FOO = 'foo';
case BAR = 'bar';
case BAZ = 'baz';
public function display(): string
{
return match ($this) {
self::FOO => __('enums/foo'),
self::BAR => __('enums/bar'),
self::BAZ => __('enums/baz'),
};
} |
Beta Was this translation helpful? Give feedback.
-
I don't believe, enum values should be used for this (directly). There's also |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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
Dom
Beta Was this translation helpful? Give feedback.
All reactions