An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          



Laravel Eloquent Translatable Logo

Laravel Eloquent Translatable


High performance, developer-first translations for Laravel models.


Latest Version on Packagist
Total Downloads
GitHub Actions
License

---

**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.