Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Enhancing Laravel: Introducing Enum Translation for a Seamless Developer Experience#49464

Unanswered
domthomas-dev asked this question inIdeas
Discussion options

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

You must be logged in to vote

Replies: 5 comments 1 reply

Comment options

Something like this
https://gist.github.com/domthomas-dev/78e1db6da82512b716b0f8cac6dd93e7#file-localizedenum-php

You must be logged in to vote
0 replies
Comment options

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.

https://github.com/domthomas-dev/laravel-localized-enum

You must be logged in to vote
0 replies
Comment options

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'),        };    }
You must be logged in to vote
1 reply
@domthomas-dev
Comment options

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.

Comment options

I don't believe, enum valuesshould be used for this (directly).

There's alsoiteks/laravel-enum to achieve something similar to@browner12's comment with attributes.

You must be logged in to vote
0 replies
Comment options

I have created a package that manages Enum translation in an elegant way
https://github.com/osama-98/laravel-enum-translatable

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
Labels
None yet
4 participants
@domthomas-dev@browner12@shaedrich@osama-98

[8]ページ先頭

©2009-2025 Movatter.jp