承接 ildaviz/filament-language-tab 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ildaviz/filament-language-tab

Composer 安装命令:

composer require ildaviz/filament-language-tab

包简介

A Laravel package to add a language tab to the Filament admin panel

README 文档

README

Administers multi-language content in tabs. Each tab is divided by language. You can go and customize the label or tab content to your liking. In addition, there is a Facade to also use this system in modals or wherever you like. An easy way to manage multi-language sites with Filament!

Preview

preview

Installation

composer require ildaviz/filament-language-tab:dev-main

Publish the configuration:

php artisan vendor:publish
select: Tag: filament-language-tab-config

Set Spatie Translatable on models

namespace App\Models;

use Spatie\Translatable\HasTranslations;

class Posts extends Model
{
    ...

    use HasTranslations;

    public $translatable = [
        'title',
        'content',
        'slug',
        'images',
        ...
    ];
    
    ...
}

Usage for resources

  1. Add on config/filament-language-tab.php your languages.
  2. Add this element on your create and edit page.

Add on Crate page and Edit page this "use" statement.

use FilamentLanguageTab\Concerns\UseTranslatablePage;

class CreatePost ...
{
    use UseTranslatablePage;
    
    ...
use FilamentLanguageTab\Concerns\UseTranslatablePage;

class EditPost ...
{
    use UseTranslatablePage;
    
    ...

Add these methods to change the locales or translatable attributes for a given page

public function setTranslatableLocales(): array
{
    return [
        'en',
        'es',
        'fr',
    ];
}

public function setTranslatableAttributes(): array
{
    return [
        'title',
        'content',
        'slug',
        'images',
    ];
}
  1. Add on your form this component. Example:
use FilamentLanguageTab\Components\TabsTranslatable;
use FilamentLanguageTab\Facades\LanguageTab;

TabsTranslatable::make('translations')
    ->makeForm(
        // Use the "lang" props to have the language cycled
        // You can also use the other Filament closures.
        getLabelTab: function ($lang) {
            return 'Translations ' . $lang;
        },
        // Use the "lang" props to have the language cycled
        // You can also use the other Filament closures.
        getFormTranslatableContent: function ($lang) {
            return [
                Forms\Components\Group::make([
                    Forms\Components\TextInput::make(LanguageTab::makeName('title', $lang))
                        ->label(__(LanguageTab::makeName('title', $lang)))
                        ->placeholder(__(LanguageTab::makeName('placeholder', $lang)))
                        ->required(),
                    Forms\Components\Textarea::make(LanguageTab::makeName('content', $lang))
                        ->label(__(LanguageTab::makeName('content', $lang)))
                        ->placeholder(__(LanguageTab::makeName('content', $lang)))
                        ->required(),
                    Forms\Components\TextInput::make(LanguageTab::makeName('slug', $lang))
                        ->label(__(LanguageTab::makeName('slug', $lang)))
                        ->placeholder(__(LanguageTab::makeName('slug', $lang)))
                        ->required(),
                    Forms\Components\FileUpload::make(LanguageTab::makeName('images', $lang))
                        ->multiple()
                        ->label(__(LanguageTab::makeName('images', $lang)))
                        ->placeholder(__(LanguageTab::makeName('images', $lang)))
                        ->required(),
                ])
            ];
        }
    )

TabsTranslatable is a wrapper for the Tabs component. It is used to create a tab for each language and to manage the translations of the fields.

To add custom languages.

->languages(['en', 'es', 'fr'])

For create the form for each language.

->makeForm(
    // Use the "lang" props to have the language cycled
    // You can also use the other Filament closures.
    getLabelTab: function (string $lang) {}
    // Use the "lang" props to have the language cycled
    // You can also use the other Filament closures.
    getFormTranslatableContent: function (string $lang) {}
)

Add correct label for fields.

LanguageTab::makeName('{name of field}', $lang)

//example:
LanguageTab::makeName('title', $lang)

//result:
'title-en'

Usage on modals or other components

// Use LanguageTab facade.

use FilamentLanguageTab\Facades\LanguageTab;

// Initialize the LanguageTab facade.
init()
// For change locales (optional)
setTranslatableLocales(array $locales = [])
// Set the translatable attributes from the specific model.
getTranslatableAttributes(string $modelClass)
// Set the translatable attributes. (optional)
setTranslatableAttributes(array $translatableAttributes = [])
// Use before create event
beforeCreate(string $modelClass, array $data)
// Use before fill event
beforeFill(Model $model, array $data)
// Use before save event
beforeSave(Model $model, array $data)
// Get the locales from the configuration.
array getLocales()
// Make the name of the field for the form.
string makeName(string $name, string $locale)

Issue Reporting

Please report any problems or bugs in the dedicated issues section on GitHub. Contributions and suggestions are welcome.

License

This package is distributed under the MIT license. For more information, refer to the LICENSE file.

ildaviz/filament-language-tab 适用场景与选型建议

ildaviz/filament-language-tab 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 49 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 ildaviz/filament-language-tab 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-12