zakafk/filament-translatable-select 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zakafk/filament-translatable-select

最新稳定版本:v1.0.3

Composer 安装命令:

composer require zakafk/filament-translatable-select

包简介

This package adds a way to interact with zakafk/translatable-select in Filament.

README 文档

README

This package adds a way to make all filament inputs translatable. It uses the spatie/laravel-translatable package in the back.

Installation

First install and configure your model(s) to use the spatie/laravel-translatable package.

You can install the package via composer:

composer require zakafk/filament-translatable-select

Add the plugin to your desired Filament panel:

use Zakafk\FilamentTranslatableSelect\Filament\Plugins\FilamentTranslatableSelectPlugin;

class FilamentPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugins([
                FilamentTranslatableSelectPlugin::make(),
            ]);
    }
}

You can specify the supported locales:

use Zakafk\FilamentTranslatableSelect\Filament\Plugins\FilamentTranslatableSelectPlugin;

class FilamentPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugins([
                FilamentTranslatableSelectPlugin::make()
                    ->supportedLocales([
                        'en' => 'English',
                        'ka' => 'Georgia',
                    ])
                    ->setLocaleHidden(false),
            ]);
    }
}

By default, the package will use the app.locale if you don't specify the locales.

Combining with the official spatie-laravel-translatable-plugin?

This package is a replacement for the official on the create and edit pages only. If you are already using the official package, you will have to delete the use Translatable trait and the LocaleSwitcher header action from those pages:

-use Filament\Actions\LocaleSwitcher;
-use Filament\Resources\Pages\EditRecord\Concerns\Translatable;

class EditPage extends EditRecord
{
-    use Translatable;

    protected function getHeaderActions(): array
    {
        return [
-            LocaleSwitcher::make(),
            DeleteAction::make(),
        ];
    }
}

Usage

You can simply add ->translatable() to any field to make it translatable.

use Filament\Forms\Components\TextInput;

TextInput::make('name')
    ->label('Name')
    ->translatable(),

Disable translations dynamically

If you want to disable translations dynamically, you can set the first parameter of the ->translatable() function to true or false.

use Filament\Forms\Components\TextInput;

TextInput::make('name')
    ->label('Name')
    ->translatable(false),

Overwrite locales

If you want to overwrite the locales on a specific field you can set the locales through the second parameter of the ->translatable() function.

use Filament\Forms\Components\TextInput;

TextInput::make('name')
    ->label('Name')
    ->translatable(true, ['en' => 'English', 'ka' => 'Georgia', 'fr' => 'French']),

Locale specific validation rules

You can add locale specific validation rules with the third parameter of the ->translatable() method.

use Filament\Forms\Components\TextInput;

TextInput::make('name')
    ->label('Name')
    ->translatable(true, null, [
        'en' => ['required', 'string', 'max:255'],
        'ka' => ['nullable', 'string', 'max:255'],
    ]);

Good to know

This package will substitute the original field with a Filament\Forms\Components\Tabs component. This component will render the original field for each locale.

All chained methods you add before calling ->translatable() will be applied to the original field. All chained methods you add after calling ->translatable() will be applied to the Filament\Forms\Components\Tabs component.

Laravel support

Laravel Version Package version
^11.0 ^1.0.2, ^2.0.0
^10.0 ^1.0.0, ^2.0.0

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

MIT License (MIT). Read the License File for more information.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-25