aaix / eloquent-translatable
High performance translations for Laravel models.
Requires
- php: ^8.1
- illuminate/console: >=10.0.0
- illuminate/contracts: >=10.0.0
- illuminate/database: >=10.0.0
- illuminate/filesystem: >=10.0.0
- illuminate/support: >=10.0.0
Requires (Dev)
- astrotomic/laravel-translatable: ^11.16
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- spatie/laravel-translatable: ^6.11
README
Laravel Eloquent Translatable
High performance, developer-first translations for Laravel models.
Eloquent Translatable is a Laravel package built for raw performance and a clean, focused developer experience. It uses direct, indexed database queries instead of relying on JSON columns or complex Eloquent model hydration, making it significantly faster and more memory-efficient than other solutions.
Key Features
- 🚀 Performance-First: Designed for speed at scale. No Eloquent overhead, no JSON parsing.
- ✨ Intuitive API: A clean, fluent, and predictable interface.
- 🤝 Spatie-Compatible: Optional API compatibility with
spatie/laravel-translatable
. - 🔒 Secure by Default: Explicitly define which attributes are translatable.
- ⚙️ Artisan Command: Scaffold translation migrations with a single command.
- 🛡️ Enum-Powered: Ships with a
Locale
enum for type-safe, readable code.
Documentation
For the full documentation, please visit our documentation website.
Installation
You can install the package via Composer:
composer require aaix/eloquent-translatable
Quick Example
-
Prepare your model:
// app/Models/Product.php namespace App\Models; use Aaix\EloquentTranslatable\Traits\HasTranslations; use Illuminate\Database\Eloquent\Model; class Product extends Model { use HasTranslations; public array $translatable = ['name', 'description']; }
-
Store and access translations:
use Aaix\EloquentTranslatable\Enums\Locale; $product = Product::create(['name' => 'My awesome product']); // Store a translation $product->storeTranslation('name', Locale::GERMAN, 'Mein tolles Produkt'); // Access it (will fall back to the app's locale) app()->setLocale('de'); echo $product->name; // Output: Mein tolles Produkt // Or get a specific locale echo $product->getTranslation('name', Locale::GERMAN); // Output: Mein tolles Produkt
Testing
To run the package's test suite, clone the repository and run:
composer install
composer test
Contributing
Contributions are welcome!
License
The MIT License (MIT). Please see License File for more information.