Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GeorgeKala's avatar

How to Implement Multilingual Enums in Laravel for API Responses with Translations

I'm building an API in Laravel and want to implement enums with multilingual support. For example, I have a CONNECTION_TYPE enum with values like WIRED and WIRELESS. I want to display these values in both English and Georgian depending on the user's locale.

My goal is:

  • To use enums for clean code and type safety.
  • To have translations for enum values in both English and Georgian.
  • To return API responses with the translated labels based on the locale.

What is the best way to achieve this? If possible, please share best practices and examples of using enums with Laravel's localization feature for such scenarios.

0 likes
4 replies
dolladolla's avatar

ძმას გაუმარჯოს, For multi language purposes i have used label() method.

this way label will be translated for showing in different language in front-end and value will stay same because in Options type of form you would not want to choose different values for same field in database.

You may ask why would you make label translatable instead of just using name, because:

The name (WIRED, WIRELESS) is used internally in code for programming purposes. Keeping it in English makes the code more maintainable and readable. The value (wired, wireless) is used in databases, URLs, or as identifiers. These need to be consistent and shouldn't change with language to avoid breaking database queries or URLs. The label is specifically meant for display to end users, so it makes sense for this to be the translatable part.

GeorgeKala's avatar

@dolladolla გაუმარჯოს, გაუმარჯოს, This is the situation that I have many Enums that can be translated, for example this Connection_type and many others, it should have the English values ​​Wired and Wireless, სადენიანი and უსადენო in Georgian, also i am interested how to save it in db, what is the best practice to make this, and is the correct way to return every enum which i have together with API?

dolladolla's avatar

@GeorgeKala This is my opinion but in database i think you should save only values of enums. you should define name and labels for that corresponding value in enum class, and name is what you use while writing code like calling the enum in controller or service or a model, so it also needs to be in english, and as i said earlier label should be the only thing that should be translatable. this is the convention we follow in my company. also we use casting in model for those translatable enums like this protected $casts = [ 'connection_type' => ConnectionType::class ]; This automatically converts the string value stored in the database ('wired' or 'wireless') into a proper ConnectionType enum instance when you retrieve the model. and we write translations for those labels in laravel's lang folder { "connection_types": [ { "value": "wired", "label": "სადენიანი" }, { "value": "wireless", "label": "უსადენო" } ] } like this.

Please or to participate in this conversation.