kaantanis / filament-tab-translatable
这是我提供的包filament-tab-translatable
2.0.1
2023-11-15 16:26 UTC
Requires
- php: ^8.1
- filament/filament: ^3.0
- illuminate/contracts: ^10.0
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
README
这个包可能没有Spatie包那样全面和有用。这个包的目的是在数据库某些列以JSON格式存储数组数据时在这里存储。在这个过程中,使用了Filament的Tab组件。给定的键会根据语言自动分隔。因此,如果发送了"title"键,它将按以下方式通过选项卡返回现有语言:"title.en, title.tr."
安装
您可以通过composer安装此包
composer require kaantanis/filament-tab-translatable
您可以通过以下方式发布配置文件(如果未自动发布):
php artisan vendor:publish --tag="filament-tab-translatable-config"
您可以在配置文件中添加新语言
这是已发布配置文件的内容
return [ 'default' => 'en', // for first tab 'laravellocalization' => false, // if you use mcamara/laravel-localization package 'tab-type' => 'code', // code or name (code: tr, en, name: Türkçe, English) default: code 'list' => [ 'tr' => [ 'name' => 'Turkish', 'native_name' => 'Türkçe', 'code_upper' => 'TR', 'code_lower' => 'tr', 'flag' => 'tr', ], 'en' => [ 'name' => 'English', 'native_name' => 'English', 'code_upper' => 'EN', 'code_lower' => 'en', 'flag' => 'gb', ], ], ];
用法
FilamentTabTranslatable::make() ->untranslatable([ TextInput::make('category') ->required(), FileUpload::make('image') ->image() ->directory('posts') ->required(), ]) ->translatable([ TextInput::make('title') ->required(), TextInput::make('slug') ->required(), Textarea::make('body') ->required(), ], 'columnName') ->render() // columnName for nested, not required if you want to use same key (columnName->anotherColumnName) // IMPORTANT: render() method is required for render the component // untranslatable() method is for non-translated columns // IMPORTANT: Make sure field type is json in database // The second parameter 'columnName' is only for translated columns. Not required if the column name is the same as the key.
渲染类型
->render(:contained: false) // default true // More details: https://filamentphp.com/docs/3.x/infolists/layout/tabs#removing-the-styled-container
示例
// Open Your Model and add trait use KaanTanis\FilamentTabTranslatable\Traits\HasTranslations; class Post extends Model { use HasTranslations; protected $guarded = []; public $translatable = ['title', 'body', 'slug']; // for $model->title etc. access } // You ready to go
// You can call directly $post->title; // returns title of app()->getLocale() language // IMPORTANT: Not working with nested json fields. Don't forget to define columns for public $translatable = [...] // if you want to get specific language $post->translate('columnName.title', 'en'); // returns title of en language $post->translate('columnName.title', 'tr'); // returns title of tr language $post->translate('columnName.title'); // returns title of app()->getLocale() language // if second parameter is not given, it returns directly by key $post->translate('description'); // not nested // or shortly $post->tt('title');
开发者说明
正如我之前提到的,这个包不如Spatie全面,可能存在一些问题。我将继续开发这个包,并使其更好,在这个过程中,那些想支持这个包开发的朋友可以毫不犹豫地做出贡献。Filament需要这样的包。谢谢。
需要什么?
- 测试
- 更好的文档
- 通过属性访问嵌套JSON字段。例如,$post->fields->title 或 $post->fields['title']
测试
composer test
更新日志
有关最近更改的更多信息,请参阅更新日志。
贡献
有关详细信息,请参阅贡献指南。
安全漏洞
请查看我们的安全策略,了解如何报告安全漏洞。
致谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。