https://github.com/jonaaix/eloquent-translatable
High performance translations for Laravel Eloquent models
https://github.com/jonaaix/eloquent-translatable
eloquent i18n laravel localization performance translation translations
Last synced: 5 months ago
JSON representation
High performance translations for Laravel Eloquent models
- Host: GitHub
- URL: https://github.com/jonaaix/eloquent-translatable
- Owner: jonaaix
- License: mit
- Created: 2025-07-20T23:28:31.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-31T15:01:58.000Z (11 months ago)
- Last Synced: 2025-10-11T21:14:54.481Z (9 months ago)
- Topics: eloquent, i18n, laravel, localization, performance, translation, translations
- Language: PHP
- Homepage: https://jonaaix.github.io/eloquent-translatable/
- Size: 845 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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
fast and memory-efficient.
## Key Features
- **✨ Intuitive API:** A clean, fluent, and predictable interface.
- **🤝 Spatie-Compatible:** Optional API compatibility with `spatie/laravel-translatable`.
- **🚀 Performance-First:** Designed for speed at scale. No Eloquent overhead, no JSON parsing.
- **🔒 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](https://jonaaix.github.io/eloquent-translatable)**.
## Installation
You can install the package via Composer:
```bash
composer require aaix/eloquent-translatable
```
## Quick Example
1. **Prepare your model:**
```php
// 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'];
}
```
2. **Store and access translations:**
```php
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:
```bash
composer install
composer test
```
## Contributing
Contributions are welcome!
## License
The MIT License (MIT). Please see [License File](LICENSE) for more information.