kaantanis/filament-model-translatable 问题修复 & 功能扩展

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

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

kaantanis/filament-model-translatable

最新稳定版本:v0.1.0-alpha

Composer 安装命令:

composer require kaantanis/filament-model-translatable

包简介

This is my package filament-model-translatable

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Filament model translatable is a package that provides a trait to make your models translatable in Laravel Filament. The data is stored in a new table with the model's id, the field name, the language, and the value.

Screenshot Screenshot

Installation

You can install the package via composer:

composer require kaantanis/filament-model-translatable

You can publish and run the migrations with:

php artisan vendor:publish --tag="filament-model-translatable-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="filament-model-translatable-config"

This is the contents of the published config file:

<?php
return [
    // except default locale on your app.php
    'supported_locales' => [
        'tr',
        'de',
    ],

    'cache_time' => 10, // in minutes
];

Usage

// model
use KaanTanis\FilamentModelTranslatable\Traits\ModelTranslatable;

class Post extends Model
{
    use ModelTranslatable;

    protected $translatable = [
        'title',
        'body',
    ];
}
// Resource
TextInput::make('title')
    ->translatable() // It works magically via macro
// Get the value
$model->title // It will return the value of the app()->getLocale()
$model->getTranslation('title', 'tr') // It will return the value of the target locale

// if the given locale does not exist from database, it will return the title of the model itself

Important Notice

When using the translatable method, the ->translatable() method must be called the last. Otherwise, other methods will not work.

When using Select component, be sure to use the ->options() method after the ->translatable() method.

// This will all work
TextInput::make('title')
    ->required()
    ->translatable()

// This will only main component field required but other cloned translatable components will not be require
// But still translatable
TextInput::make('title')
    ->translatable()
    ->required()

We need new ideas for version 2.0.0. Please open a discussion for your ideas.

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

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