PHPackages                             rodrigofs/filament-smart-translate - 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. rodrigofs/filament-smart-translate

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

rodrigofs/filament-smart-translate
==================================

A comprehensive Laravel package for automatic translation support in Filament v4 applications with advanced fallback strategies.

v2.1.0(7mo ago)8151[4 PRs](https://github.com/rodrigofs/filament-smart-translate/pulls)MITPHPPHP ^8.2CI passing

Since Sep 5Pushed 4mo agoCompare

[ Source](https://github.com/rodrigofs/filament-smart-translate)[ Packagist](https://packagist.org/packages/rodrigofs/filament-smart-translate)[ Docs](https://github.com/rodrigofs)[ RSS](/packages/rodrigofs-filament-smart-translate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (10)Used By (0)

Filament Smart Translation
==========================

[](#filament-smart-translation)

[![Tests](https://github.com/rodrigofs/filament-smart-translate/actions/workflows/run-tests.yml/badge.svg)](https://github.com/rodrigofs/filament-smart-translate/actions/workflows/run-tests.yml)[![PHPStan](https://github.com/rodrigofs/filament-smart-translate/actions/workflows/phpstan.yml/badge.svg)](https://github.com/rodrigofs/filament-smart-translate/actions/workflows/phpstan.yml)[![Code Style](https://github.com/rodrigofs/filament-smart-translate/actions/workflows/fix-code-style.yml/badge.svg)](https://github.com/rodrigofs/filament-smart-translate/actions/workflows/fix-code-style.yml)

[![License](https://camo.githubusercontent.com/9218332452902d9e542a100d0af126fd3174a116456614d2cf093546a13783db/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/9218332452902d9e542a100d0af126fd3174a116456614d2cf093546a13783db/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666f722d7468652d6261646765)[![Packagist Downloads](https://camo.githubusercontent.com/17845c649e1c7fbf9c777163a7038530b0e8c94f6c8155fe9bfadd394c48b500/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f647269676f66732f66696c616d656e742d736d6172742d7472616e736c6174653f7374796c653d666f722d7468652d6261646765266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/17845c649e1c7fbf9c777163a7038530b0e8c94f6c8155fe9bfadd394c48b500/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f647269676f66732f66696c616d656e742d736d6172742d7472616e736c6174653f7374796c653d666f722d7468652d6261646765266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)[![Filament v4](https://camo.githubusercontent.com/b1cc17ea8fe495f2e9a8841215e4c682348ca8fc494bee91e9865519633f1980/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46696c616d656e742d76342e302b2d4646364233353f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)](https://camo.githubusercontent.com/b1cc17ea8fe495f2e9a8841215e4c682348ca8fc494bee91e9865519633f1980/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f46696c616d656e742d76342e302b2d4646364233353f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)[![Laravel](https://camo.githubusercontent.com/cc65ccdef34547ff475b69a4f7e109c5ee4817e5a2fe6ab2b8b3dcf9771097ef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d7631322b2d4646324432303f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)](https://camo.githubusercontent.com/cc65ccdef34547ff475b69a4f7e109c5ee4817e5a2fe6ab2b8b3dcf9771097ef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d7631322b2d4646324432303f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)[![PHP](https://camo.githubusercontent.com/233addbd8bc6c491cd7a929fd0305ab4d0144a078f8f346dfeb9421d929ac128/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322b2d3737374242343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870)](https://camo.githubusercontent.com/233addbd8bc6c491cd7a929fd0305ab4d0144a078f8f346dfeb9421d929ac128/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322b2d3737374242343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870)

**Complete translation solution for Filament v4** that provides automatic translation for all components with zero configuration, plus a powerful translation management interface for development.

✨ Features
----------

[](#-features)

- **🎯 Zero Configuration**: Form fields, columns, actions work instantly
- **🔧 Simple Traits**: Resources, Pages, Clusters need one line of code
- **🎛️ Smart Fallbacks**: Intelligent fallback strategies when translations are missing
- **📱 Translation Manager**: Built-in interface to manage translations (development mode)
- **🌐 Multi-locale Support**: Full Laravel translation system support
- **📊 Status Dashboard**: Visual overview of implementation status
- **⚡ High Performance**: Optimized with caching and lazy evaluation

📦 Installation
--------------

[](#-installation)

### 1. Install Package

[](#1-install-package)

```
composer require rodrigofs/filament-smart-translate
```

### 2. Publish Configuration (Optional)

[](#2-publish-configuration-optional)

```
php artisan vendor:publish --tag=filament-smart-translate-config
```

### 3. Check Status

[](#3-check-status)

```
php artisan filament-smart-translate:status
```

🚀 Quick Start
-------------

[](#-quick-start)

### 1. Set Your Locale

[](#1-set-your-locale)

```
// config/app.php
'locale' => 'pt_BR', // or your preferred locale
```

### 2. Create Translation Files

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

```
// lang/pt_BR.json
{
    "name": "Nome",
    "email": "E-mail",
    "user": "Usuário",
    "admin": "Administração",
    "create": "Criar",
    "edit": "Editar",
    "delete": "Excluir"
}
```

### 3. Add Traits to Resources, Pages &amp; Clusters

[](#3-add-traits-to-resources-pages--clusters)

**Only for Resources, Pages, and Clusters** - other components work automatically:

```
// Resources

use Rodrigofs\FilamentSmartTranslate\Traits\Resource\ResourceTranslateble;

class UserResource extends Resource
{
    use ResourceTranslateble; // ⭐ Add this line
}

// Pages
use Rodrigofs\FilamentSmartTranslate\Traits\Page\PageTranslateble;

class Settings extends Page
{
    use PageTranslateble; // ⭐ Add this line
}

// Clusters
use Rodrigofs\FilamentSmartTranslate\Traits\Cluster\ClusterTranslateble;

class UserManagement extends Cluster
{
    use ClusterTranslateble; // ⭐ Add this line
}
```

**That's it!** Your Filament interface will now display translated labels automatically.

🎯 How It Works
--------------

[](#-how-it-works)

### ✅ Automatic (No Code Changes)

[](#-automatic-no-code-changes)

These components work instantly with **zero configuration**:

- **Form Fields**: TextInput, Select, Checkbox, etc.
- **Table Columns**: TextColumn, BooleanColumn, etc.
- **Actions**: CreateAction, EditAction, DeleteAction, etc.
- **Layout**: Section, Tabs, Group, etc.

### 🔧 Trait Required

[](#-trait-required)

These components need **one trait per class**:

- **Resources**: Model labels &amp; navigation → `ResourceTranslateble`
- **Pages**: Navigation groups → `PageTranslateble`
- **Clusters**: Breadcrumbs &amp; navigation → `ClusterTranslateble`

ComponentAutomaticTrait RequiredForm Fields✅ Yes❌ NoTable Columns✅ Yes❌ NoActions✅ Yes❌ NoLayout✅ Yes❌ No**Resources**❌ No✅ Yes**Pages**❌ No✅ Yes**Clusters**❌ No✅ Yes📱 Translation Manager (Development Feature)
-------------------------------------------

[](#-translation-manager-development-feature)

The package includes a **powerful translation management interface** for development environments.

### ⚠️ Important: Development Only

[](#️-important-development-only)

**The Translation Manager should only be used in development environments** to avoid Git conflicts during production deployments.

**The Problem**: The manager modifies JSON translation files directly. When you pull updates from Git to your production server, these local changes will conflict with incoming changes, potentially causing deployment failures or requiring manual conflict resolution during `git pull` operations.

use Filament\\Pages\\Page;use Rodrigofs\\FilamentSmartTranslate\\Traits\\Page\\PageTranslateble;

### 🔧 Enable Translation Manager

[](#-enable-translation-manager)

#### 1. Register the Plugin

[](#1-register-the-plugin)

Add the TranslationPlugin to your Filament panel:

```
// app/Providers/Filament/AdminPanelProvider.php
use Rodrigofs\FilamentSmartTranslate\TranslationPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ... other configurations
        ->plugins([
            TranslationPlugin::make(), // ⭐ Add this line
            // ... other plugins
        ]);
}
```

#### 2. Configure the Translation Manager

[](#2-configure-the-translation-manager)

Add to your configuration:

```
// config/filament-smart-translate.php
'translation_page' => [
    'enabled' => true,
    'dev_only' => true, // ⭐ Important: Only in development
    'navigation' => [
        'enabled' => true,
        'group' => 'Development',
        'sort' => 99,
        'icon' => 'heroicon-o-language',
    ],
    'page' => [
        'title' => 'Translation Manager',
        'navigation_label' => 'Translations',
    ],
    'features' => [
        'export' => true,
        'backup' => true,
        'language_selector' => true,
        'bulk_actions' => true,
    ],
    'authorize' => env('APP_DEBUG', false), // Only when debug is enabled
],
```

### 📸 Translation Manager Features

[](#-translation-manager-features)

[![Translation Manager Interface](.github/resources/print_1.png)](.github/resources/print_1.png)

*Translation Manager interface showing the translation editing capabilities*

**🌐 Multi-language Interface**

- Switch between locales instantly
- Add, edit, delete translations
- Bulk operations for efficiency

**📊 Statistics Dashboard**

- Total translations count
- Empty translations detection
- Progress tracking per locale

**💾 Backup &amp; Export**

- Automatic backups before changes
- Export translations to JSON
- Safe file handling

**🔍 Search Functionality**

- Search translations by key or value

### 🛡️ Production Alternative

[](#️-production-alternative)

If you **must** use the Translation Manager in production:

1. **Remove translation files from Git tracking**:

```
# Add to .gitignore
lang/*.json
!lang/en.json  # Keep English as template
```

2. **Configure for production**:

```
'translation_page' => [
    'enabled' => env('TRANSLATION_MANAGER_ENABLED', false),
    'dev_only' => false,
    'authorize' => function () {
        return auth()->user()?->hasRole('admin');
    },
],
```

3. **Use environment variable**:

```
# Only enable when needed
TRANSLATION_MANAGER_ENABLED=true
```

⚠️ **Recommendation**: Keep the Translation Manager in development only to avoid Git conflicts during production deployments (`git pull` operations).

🎛️ Fallback Strategies
----------------------

[](#️-fallback-strategies)

When translations are missing, the package applies intelligent fallback strategies:

### Built-in Strategies

[](#built-in-strategies)

#### 1. `original` (Default)

[](#1-original-default)

Keeps the original key format:

```
user_name → User name
email_address → Email address

```

#### 2. `humanize`

[](#2-humanize)

Converts to human-readable format:

```
user_name → User Name
emailAddress → Email Address

```

#### 3. `lower_case`

[](#3-lower_case)

Converts to lowercase with hyphens:

```
user_name → user-name
email_address → email-address

```

### Component-Specific Configuration

[](#component-specific-configuration)

```
'components' => [
    'fields' => [
        'enabled' => true,
        'fallback_strategy' => 'original'
    ],
    'resources' => [
        'enabled' => true,
        'fallback_strategy' => 'humanize'
    ],
    'actions' => [
        'enabled' => true,
        'fallback_strategy' => 'lower_case'
    ]
]
```

### Custom Strategies

[](#custom-strategies)

Create your own fallback strategy:

```
