# Localized Model Field Convention

This project does not create separate `*_ar` and `*_en` database columns. Every localized attribute is a JSON column managed by `spatie/laravel-translatable`.

## Canonical model contract

```php
use Spatie\Translatable\HasTranslations;

class Product extends Model
{
    use HasTranslations;

    /** @var list<string> */
    public array $translatable = ['name', 'description'];
}
```

The database columns are:

```php
$table->json('name')->nullable();
$table->json('description')->nullable();
```

Values are stored as `{\"ar\": \"...\", \"en\": \"...\"}` and can be accessed with `$product->getTranslation('name', 'ar')` or `$product->name` for the current locale.

## Legacy mapping

| Legacy pair | Canonical JSON attribute | Keys |
| --- | --- | --- |
| `name_arabic`, `name_english` | `name` | `ar`, `en` |
| `title_arabic`, `title_english` | `title` | `ar`, `en` |
| `description_arabic`, `description_english` | `description` | `ar`, `en` |
| `content_arabic`, `content_english` | `content` | `ar`, `en` |
| `code_arabic`, `code_english` | `code` | `ar`, `en` |
| `question_arabic`, `question_english` | `question` | `ar`, `en` |

The importer must write each legacy value to its corresponding locale key and must not retain the old language-specific columns.

## Filament contract

```php
TextInput::make('name')
    ->translatable();
```

The `alareqi/filament-translatable-fields` plugin is registered on the admin panel with Arabic and English supported locales. Use `->translatable()` only for fields listed in the model’s `$translatable` array.
