---
name: zeus-translatable-pro
description: Use when installing, configuring, or building with lara-zeus/translatable-pro database-backed model phrases, MultiLang forms, table search/sort macros, custom phrase models, or AI translations.
---

# Lara Zeus Translatable Pro (`lara-zeus/translatable-pro`)

## Overview & Requirements
`lara-zeus/translatable-pro` stores Eloquent translations in a normalized `phrases` table with Filament `MultiLang` tabs, `TextColumn` search/sort macros, locale switching, and AI translation.
- **PHP**: `^8.3`
- **Dependencies**: `filament/filament` (`^5.0`), `lara-zeus/filament-plugin-tools` (`^3.0`), `laravel/ai` (`^0.8`), `reedware/laravel-relation-joins` (`^9.0`)

## Installation
Configure the Lara Zeus private Satis repository and license credentials in `auth.json` (from your `https://larazeus.com/dashboard` account):
```bash
composer config repositories.larazeus composer https://larazeus.com/satis
composer require lara-zeus/translatable-pro
php artisan translatable-pro:install
```
`php artisan translatable-pro:install` publishes `zeus-translatable-pro-migrations` (`create_phrases_table`) and `zeus-translatable-pro-config`, then optionally runs `php artisan migrate`.

## Configuration & Migrations
Key options in `config/zeus-translatable-pro.php`:
- `languages`: `[['name' => 'English', 'code' => 'en']]`
- `lang_switcher.enabled`: `true` (renders locale switcher in `PanelsRenderHook::GLOBAL_SEARCH_AFTER`)
- `auto_phraseable`: `true` (auto-applies `->phraseable()` on translatable `TextColumn`s and `with(['phrases'])` on Filament tables)
- `models.Phrase`: `LaraZeus\TranslatablePro\Models\Phrase::class`
- `fallback_lang`: `'en'`, `register_phrase_resource`: `true`
- `ai_provider`: `'gemini'`, `ai_model`: `'gemini-3.5-flash'`, `ai_agent_notes`: `null`

## Filament Panel Registration
```php
use LaraZeus\TranslatablePro\TranslatableProPlugin;

->plugins([
    TranslatableProPlugin::make()
        ->navigationGroupLabel('Translations'),
])
```

## Core Usage & Examples

### 1. Model Setup (`HasPhrases` + `PhrasesCast`)
```php
use Illuminate\Database\Eloquent\Model;
use LaraZeus\TranslatablePro\Casts\PhrasesCast;
use LaraZeus\TranslatablePro\Models\Concerns\HasPhrases;

class Book extends Model
{
    use HasPhrases;

    protected $casts = [
        'title' => PhrasesCast::class,
        'desc' => PhrasesCast::class,
    ];
}
```
Migrate existing column data into `phrases`: `php artisan zeus-translatable-pro:setup Book`.
Generate a dedicated phrase model/table for a model: `php artisan zeus-translatable-pro:make:model Phrases/Book`.

### 2. Filament Forms & Tables
```php
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Tables\Columns\TextColumn;
use LaraZeus\TranslatablePro\Filament\Forms\Components\MultiLang;

MultiLang::make('title')
    ->require(['en'])
    ->disable(['fr'])
    ->default(['en' => '', 'ar' => '']);

MultiLang::make('desc')
    ->setTabSchema(RichEditor::make('desc'));

// Relation Select search across phrases:
Select::make('cat_id')->relationship('cat', 'name')->phrasesSearchable();

// Manual table macros (when auto_phraseable is false):
TextColumn::make('title')->phraseable(); // or ->phraseSearchable()->phraseSortable()
```

### 3. AI Translation
Publish Laravel AI config and set your API key (e.g., `GEMINI_API_KEY` in `.env`):
```bash
php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider"
php artisan queue:work # required for TranslatePhrasesBulk
```
Programmatic usage: `PhraseAiTranslator::translateRow($phrase);`.

## Common Pitfalls
- **Missing `PhrasesCast`**: Without `'attr' => PhrasesCast::class` in `$casts`, `TranslatablePro::getTranslatableAttributes()` returns empty and `HasPhrases` will not save phrases.
- **PHPStan errors on `phraseable()`**: Add `vendor/lara-zeus/translatable-pro/phpstan/stubs/Filament/Tables/Columns/TextColumn.stub` to `phpstan.neon` `stubFiles`.
- **Bulk AI translation stalled**: Bulk actions dispatch `TranslatePhrasesBulk` to the queue; ensure a queue worker is running.
