Download the PHP package mohamedbakr57/localized-enum without Composer
On this page you can find all versions of the php package mohamedbakr57/localized-enum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mohamedbakr57/localized-enum
More information about mohamedbakr57/localized-enum
Files in mohamedbakr57/localized-enum
Package localized-enum
Short Description A simple and lightweight Laravel package that adds localized labels to native PHP enums using Laravel's translation system. Ideal for multi-language applications.
License MIT
Homepage https://github.com/mohamedbakr57/localized-enum
Informations about the package localized-enum
Localized Enum for Laravel
Localized Enum is a simple, lightweight Laravel package that adds localized labels to native PHP enums using Laravelβs translation system.
Perfect for multilingual applications and API responses with dynamic localization support.
π Table of Contents
- Usage
- Basic Usage
- Custom Translation Key
- Fallback Default
- Locale from Request Header
- Override Header Key
- Features
- Installation
- Example Translation File
- Testing
- Development
- License
- Credits
π§ͺ Usage
Basic Usage
Custom Translation Key
Fallback Default
Locale from Request Header
If you're building an API and send locale via headers:
The trait will use the X-Locale
value automatically.
π Default header key is
X-Locale
, but it can be overridden.
Override Header Key
If your app uses a different header, override the method in your enum:
Or override getLabelLocale()
entirely for full control.
β¨ Features
- π·οΈ Adds
label()
method to native PHP Enums - π Fully supports Laravelβs translation system
- π§ Smart fallback resolution (from multiple key patterns)
- π§ͺ Works great in API responses
- π§ Easily override locale detection via request headers
- π Defaults to
config('app.locale')
if no locale is sent - β‘ Compatible with flat or nested translation files
π¦ Installation
π Example Translation File
Supports both:
enums.FQCN.CASE
enums.Basename.CASE
FQCN.CASE
Basename.CASE
- Or just:
'Approved' => 'Approved Label'
for flat key fallback
β Requirements
- PHP: ^8.1
- Laravel: ^10.0, ^11.0, ^12.0
π§ͺ Testing
Run Pint for formatting:
π§° Development
π License
Licensed under MIT License
π Credits
Built and maintained by Mohamed Bakr
Stars and PRs are welcome βοΈ
All versions of localized-enum with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0 || ^11.0 || ^12.0