mvenghaus/filament-plugin-translatable-inline 问题修复 & 功能扩展

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

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

mvenghaus/filament-plugin-translatable-inline

Composer 安装命令:

composer require mvenghaus/filament-plugin-translatable-inline

包简介

An alternative to https://github.com/filamentphp/spatie-laravel-translatable-plugin. The difference is that all translations occur directly under each field.

README 文档

README

This is an addon to Spatie Translatable that allows you to edit your translation directly below the field.

This approach offers several advantages:

  • Faster editing of your translations
  • Detecting fields that can be translated is much easier to see
  • You can quickly see which translations are missing

Screenshots

Screenshot

Requirements

You need the latest version of Filament v3.

This package is based on:

You don't need to install them separately, it's handled via dependencies.

Installation

Install the package via composer:

composer require mvenghaus/filament-plugin-translatable-inline:"^3.0"

Configuration

Since it is based on the Spatie plugin, it must be registered as described in the documentation.

NOTE: It is important that you don't add the traits and the header action to your form resource pages, or it won't work! Only the trait "Translatable" in your resource is required!

Instead of having a locale switcher in a dropdown above, you add a container for each translatable field.

Before

<?php

...

    public static function form(Form $form): Form
        {
            return $form
                ->schema([
                    Forms\Components\TextInput::make('title')
                        ->maxLength(255)
                        ->required()
                    ,

...

After

<?php

...

use Mvenghaus\FilamentPluginTranslatableInline\Forms\Components\TranslatableContainer;

...

    public static function form(Form $form): Form
        {
            return $form
                ->schema([
                    TranslatableContainer::make(
                        Forms\Components\TextInput::make('title')
                            ->maxLength(255)
                            ->required()
                    )
                       ->onlyMainLocaleRequired() // optional
                       ->requiredLocales(['en', 'es']) // optional
                    ,

...

For each field that can be translated, simply repeat this process, and you'll be done.

NOTE: You don't have to globally choose between inline or dropdown. Instead, you can choose an option on each page. For instance, it makes sense to have the dropdown in the list view and then use the inline version when editing.

Options

onlyMainLocaleRequired

Sometimes you might want the field to be required, but only for the primary language. For example, if you set the TextInput to 'required,' it applies to all language variants. This is where this option comes into play. It removes the 'required' validation for all other languages except the primary one.

requireLocales

If you have more than one required locales you can pass an array to this method.

Tipps & Hints

Validation

If all of your locales are required and if your values do not pass the JS validation, then the variants will remain automatically expanded.

afterStateUpdated

If you want to use "afterStateUpdated", you have to consider that the state path shifts by one level. n addition, one must specify the locale which is located in the component's meta under the key "locale".

Before

->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))),

After

->afterStateUpdated(fn (Set $set, Component $component, ?string $state) => $set('../slug.' . $component->getMeta('locale'), Str::slug($state))),

Empty translations

Screenshot

As you can see in the screenshot, the "nl" is not filled and therefore not marked.

Contact

If you any questions or you find a bug, please contact me via email.

mvenghaus/filament-plugin-translatable-inline 适用场景与选型建议

mvenghaus/filament-plugin-translatable-inline 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48.94k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2024 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「translatable」 「inline」 「laravel」 「spatie」 「filament」 「mvenghaus」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mvenghaus/filament-plugin-translatable-inline 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mvenghaus/filament-plugin-translatable-inline 我们能提供哪些服务?
定制开发 / 二次开发

基于 mvenghaus/filament-plugin-translatable-inline 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 48.94k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 26
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-08