承接 kongulov/nova-tab-translatable 相关项目开发

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

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

kongulov/nova-tab-translatable

Composer 安装命令:

composer require kongulov/nova-tab-translatable

包简介

Making Nova Tab Translatable

关键字:

README 文档

README

Latest Version on Packagist Licence Total Downloads

This package contains a NovaTabTranslatable class you can use to make any Nova field type translatable with tabs. Use the master branch for Nova 5 and the 1.x branch for Nova 4.

Imagine you have this fields method in a Post Nova resource:

use Kongulov\NovaTabTranslatable\NovaTabTranslatable;

...

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        NovaTabTranslatable::make([
            SluggableText::make('Title')->slug('Slug'),
            Slug::make('Slug')->readonly(),
            Trix::make('text'),
            Text::make('Keywords'),
            Text::make('Description'),
        ]),
    ];
}

That Post Nova resource will be rendered like this.

screenshot screenshot

Requirements

  • php: >=7.1.0
  • spatie/laravel-translatable: ^4.0

Installation

Install the package in a Laravel Nova project via Composer:

# Install nova-tab-translatable
composer require kongulov/nova-tab-translatable

# Publish configuration
php artisan vendor:publish --tag="tab-translatable-config"

This is the contents of the file which will be published at config/tab-translatable.php

<?php

return [
    /*
     * The source of supported locales on the application
     * Available selection "array", "database". Default array
     */
    'source' => 'array',

    /*
     * If you choose array selection, you should add all supported translation on it as "code"
     */
    'locales' => [
        'en', 'fr', 'es'
    ],

    /*
     * If you choose database selection, you should choose the model responsible for retrieving supported translations
     * And choose the 'code_field' for example "en", "fr", "es"...
     */
    'database' => [
        'model' => 'App\\Models\\Language',
        'code_field' => 'lang',
        'sort_by' => 'id',
        'sort_direction' => 'asc'
    ],

    /*
     * If you want to save the tab in the last selected language for the whole project, set this "true".
     * But if you want to use in one place call the saveLastSelectedLang(true|false) method
     */
    'save_last_selected_lang' => false,
];

Usage

You must prepare your model as explained in the readme of laravel-translatable. In short: you must add json columns to your model's table for each field you want to translate. Your model must use the Spatie\Translatable\HasTranslations on your model. Finally, you must also add a $translatable property on your model that holds an array with the translatable attribute names.

Now that your model is configured for translations, you can use NovaTabTranslatable in the related Nova resource. Any fields you want to display in a multilingual way can be passed as an array to NovaTabTranslatable.

use Kongulov\NovaTabTranslatable\NovaTabTranslatable;

...

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        NovaTabTranslatable::make([
            SluggableText::make('Title')->slug('Slug'),
            Slug::make('Slug')->readonly(),
            Trix::make('text'),
            Text::make('Keywords'),
            Text::make('Description'),
        ]),
    ];
}

If you want to make the field required only in certain languages, then you can use the required_lang rule,

NovaTabTranslatable::make([
    Text::make('Title')->rules('required_lang:en,fr'),
    Trix::make('text')->rules('required_lang:en,fr'),
    Text::make('Keywords'),
    Text::make('Description'),
]),

But if you want to make the field required in all languages, then use the laravel rules

NovaTabTranslatable::make([
    Text::make('Title')->rules('required'),
]),
  • Replace field name
NovaTabTranslatable::make([
    Text::make('Title')->rules('required'),
])->setTitle('Own Title'),
  • If you want to save the tab in the last selected language, call the saveLastSelectedLang() method or in the config replace 'save_last_selected_lang' => false with 'save_last_selected_lang' => true
NovaTabTranslatable::make([
    Text::make('Title'),
])->saveLastSelectedLang(true|false),
  • If on the index and detail pages you want to turn off the tab and show it each as a row, use trait TranslatableTabToRowTrait in your resource
class YourResource extends Resource
{
    use TranslatableTabToRowTrait;
    ...
}

Credits

License

This project is open-sourced software licensed under the MIT license.

kongulov/nova-tab-translatable 适用场景与选型建议

kongulov/nova-tab-translatable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 62.81k 次下载、GitHub Stars 达 85, 最近一次更新时间为 2020 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 kongulov/nova-tab-translatable 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 62.81k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 86
  • 点击次数: 24
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 85
  • Watchers: 3
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-10