PHPackages                             dyahunter35/filament-translation-toolkit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. dyahunter35/filament-translation-toolkit

ActiveLibrary[Localization &amp; i18n](/categories/localization)

dyahunter35/filament-translation-toolkit
========================================

A comprehensive translation toolkit for Filament v5 — automatic UI translation, AI-powered translation generation, and language file scaffolding.

1.0.1(yesterday)05↑2900%MITPHP ^8.2

Since Jul 19Compare

[ Source](https://github.com/dyahunter35/filament-translation-toolkit)[ Packagist](https://packagist.org/packages/dyahunter35/filament-translation-toolkit)[ Docs](https://github.com/dyahunter35/filament-translation-toolkit)[ RSS](/packages/dyahunter35-filament-translation-toolkit/feed)WikiDiscussions Synced today

READMEChangelogDependencies (8)Versions (3)Used By (0)

Filament Translation Toolkit
============================

[](#filament-translation-toolkit)

A comprehensive, production-ready translation toolkit for **Filament v5** â€” automatic UI translation, AI-powered translation generation, language file scaffolding, and a full dashboard to monitor translation health across your entire application.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Quick Start](#quick-start)
- [Dashboard](#dashboard)
- [Artisan Commands](#artisan-commands)
- [Traits (Concerns)](#traits-concerns)
- [Translation File Structure](#translation-file-structure)
- [AI Translation Service](#ai-translation-service)
- [Templating System](#templating-system)
- [How It Works](#how-it-works)
- [Publishing Assets](#publishing-assets)
- [Testing](#testing)
- [Changelog](#changelog)
- [License](#license)

---

Features
--------

[](#features)

FeatureDescription**Zero-Boilerplate Translation**Just `use HasResource;` â€” global auto-registration handles everything**Automatic UI Translation**Auto-translate Filament forms, tables, infolists, navigation, and breadcrumbs at runtime**Translation Dashboard**A full Filament page to monitor API status, missing files, completeness, and relationships**AI-Powered Generation**Generate smart translation files using OpenRouter API (GPT-4o-mini by default)**Column-Based Generation**Generate translation scaffolding directly from database table columns**Relationship Detection**Auto-discovers Eloquent relationships and checks for `_relation` translation files**Completeness Monitoring**Visual progress bars showing translation completeness per file with missing key tooltips**Per-Class Disable**Set `$translationEnabled = false` on any class to skip translation**Global Toggle**`enabled` config or `FILAMENT_TRANSLATION_ENABLED` env to disable everything**Multi-Page Support**Dedicated traits for Resources, Resource Pages, Single Pages, Relation Managers, and Pages**Multi-Language**Configurable locale list â€” add any number of languages**Extensible Templates**Strategy pattern for translation templates â€” create your own template types---

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- Laravel &gt;= 13.x
- Filament &gt;= 5.x
- `spatie/laravel-package-tools` &gt;= 1.15

---

Installation
------------

[](#installation)

### Step 1: Add the Package

[](#step-1-add-the-package)

```
composer require dyahunter35/filament-translation-toolkit
```

### Step 2: Add Views Path to Your Theme (Required for Dashboard Styling)

[](#step-2-add-views-path-to-your-theme-required-for-dashboard-styling)

To ensure Tailwind CSS v4 compiles the classes used in the Translation Dashboard, add a `@source` directive in your main CSS file:

```
/* resources/css/filament.css */
@import 'tailwindcss';
@source '../../../../vendor/dyahunter35/filament-translation-toolkit/resources/**/*.blade.php';
```

Then rebuild your assets:

```
npm run build
```

### Step 3: Publish the Config

[](#step-3-publish-the-config)

```
php artisan vendor:publish --tag=filament-translation-toolkit-config
```

This creates `config/filament-translation-toolkit.php` in your project.

### Step 4: Configure Your Locales

[](#step-4-configure-your-locales)

Open `config/filament-translation-toolkit.php`:

```
'locales' => ['en', 'ar'],  // First locale = base language
```

### Step 5: (Optional) Configure AI Translation

[](#step-5-optional-configure-ai-translation)

If you want AI-powered translation generation:

1. Create a free account at [openrouter.ai](https://openrouter.ai)
2. Generate an API key from [Keys page](https://openrouter.ai/keys)
3. Add to your `.env`:

```
OPENROUTER_API_KEY=sk-or-v1-xxxxxxxxxxxx
OPENROUTER_MODEL=openai/gpt-4o-mini
```

### Step 6: Register the Dashboard (Optional)

[](#step-6-register-the-dashboard-optional)

To add the Translation Dashboard to your Filament panel:

```
// app/Providers/Filament/AdminPanelProvider.php

use Dyahunter35\FilamentTranslationToolkit\Pages\TranslationDashboard;

public function panel(Panel $panel): Panel
{
    return $panel
        // ... other config
        ->pages([
            TranslationDashboard::class,
        ]);
}
```

#### Customizing Dashboard Navigation

[](#customizing-dashboard-navigation)

You can customize the dashboard's navigation label, group, title, icon, and sort order from the config file or via environment variables:

```
// config/filament-translation-toolkit.php
'navigation' => [
    'label' => 'My Dashboard',           // null = use __() translations
    'group' => 'Admin Tools',            // null = use __() translations
    'title' => 'Translation Overview',   // null = use __() translations
    'icon'  => 'heroicon-o-cog-6-tooth',
    'sort'  => 100,
],
```

Or via `.env`:

```
TRANSLATION_DASHBOARD_LABEL="My Dashboard"
TRANSLATION_DASHBOARD_GROUP="Admin Tools"
TRANSLATION_DASHBOARD_TITLE="Translation Overview"
TRANSLATION_DASHBOARD_ICON="heroicon-o-cog-6-tooth"
TRANSLATION_DASHBOARD_SORT=100
```

When set to `null` (default), the label, group, and title are automatically translated based on the active locale (English: "Translation Dashboard", Arabic: "لوحة التحكم بالترجمة").

### Step 7: Use Traits in Your Filament Classes

[](#step-7-use-traits-in-your-filament-classes)

Start using the translation traits in your existing classes (see [Traits](#traits-concerns) below).

---

Configuration
-------------

[](#configuration)

The full config file with all options:

```
// config/filament-translation-toolkit.php

return [

    // Master switch — disable all translation globally
    'enabled' => env('FILAMENT_TRANSLATION_ENABLED', true),

    // Locales to generate translations for (first = base)
    'locales' => ['en', 'ar'],

    // Eloquent models namespace (for relationship detection)
    'model_namespace' => 'App\\Models',

    // Translation files directory (null = base_path('lang'))
    'lang_path' => null,

    // Default Heroicon for generated files
    'default_icon' => 'heroicon-m-building-office-2',

    // AI Translation Service
    'ai' => [
        'api_key'   => env('OPENROUTER_API_KEY', ''),
        'model'     => env('OPENROUTER_MODEL', 'openai/gpt-4o-mini'),
        'endpoint'  => 'https://openrouter.ai/api/v1/chat/completions',
        'timeout'   => 45,
    ],

    // Which keys to include in generated files
    'structure' => [
        'resource' => [
            'navigation' => true,
            'breadcrumbs' => true,
            'fields' => true,
            'sections' => true,
            'filters' => true,
            'actions' => true,
            'widgets' => false,
        ],
        'relation' => [
            'label' => true,
            'fields' => true,
            'filters' => true,
            'actions' => true,
        ],
    ],

    // Models to exclude from the translation scanner
    'excluded_models' => [
        'Job',
        'Migration',
        'PasswordResetToken',
        'CacheLock',
        'FailedJob',
        'JobBatch',
        'Permission',
        'Role',
    ],

    // Dashboard navigation settings
    // Set any value to null to use translated labels from lang files
    'navigation' => [
        'label' => env('TRANSLATION_DASHBOARD_LABEL', null),
        'group' => env('TRANSLATION_DASHBOARD_GROUP', null),
        'title' => env('TRANSLATION_DASHBOARD_TITLE', null),
        'icon'  => env('TRANSLATION_DASHBOARD_ICON', 'heroicon-o-language'),
        'sort'  => (int) env('TRANSLATION_DASHBOARD_SORT', 999),
    ],

];
```

### Environment Variables

[](#environment-variables)

VariableDefaultDescription`FILAMENT_TRANSLATION_ENABLED``true`Master switch to enable/disable translation`OPENROUTER_API_KEY``''`OpenRouter API key for AI translations`OPENROUTER_MODEL``openai/gpt-4o-mini`AI model to use for translations`TRANSLATION_DASHBOARD_LABEL``null`Custom label for dashboard nav (null = translated)`TRANSLATION_DASHBOARD_GROUP``null`Custom group name for dashboard nav (null = translated)`TRANSLATION_DASHBOARD_TITLE``null`Custom page title for dashboard (null = translated)`TRANSLATION_DASHBOARD_ICON``heroicon-o-language`Custom icon for dashboard nav`TRANSLATION_DASHBOARD_SORT``999`Sort order for dashboard in sidebar---

Quick Start
-----------

[](#quick-start)

### 1. Generate Translation Files for a Table

[](#1-generate-translation-files-for-a-table)

```
# Basic â€” generates scaffolding from column names
php artisan make:table-translation companies

# AI-powered â€” generates smart translations
php artisan make:ai-translation companies --type=resource

# Relation manager
php artisan make:ai-translation documents --type=relation
```

### 2. Add the Trait to Your Resource

[](#2-add-the-trait-to-your-resource)

That's it â€” **just add the trait**. Translation is auto-activated:

```
namespace App\Filament\Resources;

use Dyahunter35\FilamentTranslationToolkit\Concerns\HasResource;
use Filament\Resources\Resource;

class CompanyResource extends Resource
{
    use HasResource;

    public static function getModel(): string
    {
        return \App\Models\Company::class;
    }

    public static function form(array $form): array
    {
        return $form->schema([
            // ... your form fields â€” labels auto-translated!
        ]);
    }
}
```

### 3. Add the Trait to Your Relation Manager

[](#3-add-the-trait-to-your-relation-manager)

```
namespace App\Filament\Resources\CompanyResource\RelationManagers;

use Dyahunter35\FilamentTranslationToolkit\Concerns\HasRelationManager;
use Filament\Resources\RelationManagers\RelationManager;

class DocumentsRelationManager extends RelationManager
{
    use HasRelationManager;

    protected static string $relationship = 'documents';
}
```

That's it â€” your UI is now automatically translated!

### 4. Disable Translation for a Specific Class

[](#4-disable-translation-for-a-specific-class)

If a page doesn't need translation, disable it per-class:

```
class InternalDashboard extends Resource
{
    use HasResource;

    public static bool $translationEnabled = false; // disables translation

    // ...
}
```

Or disable globally in `.env`:

```
FILAMENT_TRANSLATION_ENABLED=false
```

Or in config:

```
'enabled' => false,
```

### 5. Explicit Boot (Optional)

[](#5-explicit-boot-optional)

If the global auto-translation doesn't work for your setup, you can still call `bootTranslation()` explicitly:

```
class CompanyResource extends Resource
{
    use HasResource;

    public static function boot(): void
    {
        static::bootTranslation(); // calls all 3 configure methods
    }
}
```

---

Dashboard
---------

[](#dashboard)

The `TranslationDashboard` is a comprehensive monitoring page with 5 sections:

### 1. AI Service Status

[](#1-ai-service-status)

- **Green indicator**: API key is configured and ready
- **Red indicator with instructions**: Shows step-by-step setup guide including:
    - How to create an OpenRouter account
    - How to generate an API key
    - Where to add it in `.env`
    - Direct link to get the API key

### 2. Missing Translation Files

[](#2-missing-translation-files)

- Scans all database tables
- Shows which tables are missing translation files per locale
- **Generate** button — creates basic scaffolding from column names
- **AI Generate** button — uses AI to create smart translations (only shown if API is configured)
- **Loading indicators**: Each button shows a spinner during processing and becomes disabled to prevent double-clicks. A global banner appears at the top of the dashboard while any action is running.

### 3. Translation Completeness

[](#3-translation-completeness)

- Compares the base locale against all other locales
- Shows progress bars with percentages
- Displays key counts (e.g., `45/50`)
- Tooltip on missing keys shows the actual missing key names

### 4. Model Relationships

[](#4-model-relationships)

- Auto-discovers all Eloquent models from your configured namespace
- Shows all public relationship methods per model
- Green dot = translation file exists, red dot = missing
- **Create Translation** button to generate missing relation files

### 5. All Translation Files (Collapsed)

[](#5-all-translation-files-collapsed)

- Lists every translation file
- Shows key count per locale
- Highlights files that are missing in certain locales

---

Artisan Commands
----------------

[](#artisan-commands)

### `make:table-translation`

[](#maketable-translation)

Generate a basic translation file from database table columns.

```
php artisan make:table-translation {table} {--lang=}
```

ParameterDescription`{table}`The database table name`--lang`Specific locale (defaults to all configured locales)**Example:**

```
php artisan make:table-translation companies
php artisan make:table-translation companies --lang=en
```

**What it generates:**

```
// lang/en/company.php
