承接 berthott/laravel-translatable 相关项目开发

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

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

berthott/laravel-translatable

最新稳定版本:3.0.5

Composer 安装命令:

composer require berthott/laravel-translatable

包简介

Laravel Helper for Model Translations

README 文档

README

test workflow

Laravel-Translatable

A helper for Model Translations in Laravel.

Easily add translatable fields to any of your eloquent models.

Installation

$ composer require berthott/laravel-translatable

Usage / How it works

  • Create your table and corresponding model, eg. with php artisan make:model YourModel -m
  • Use the translatable macro to add translatable fields in your migration. Eg.
        Schema::create('dummies', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->translatable('user_input');
            $table->timestamps();
        });
  • Add the Translatable trait to your newly generated model.
  • Add a translatableFields() method to return an array with a list of your translatable fields to your model.
  • Use self::translatableRules to gather all the rules you need to assure the correct data format, eg.
    {
        "en": "English String",
        "de": "German String",
    }
  • If some fields should have optional languages, not listed in the packages config, you can add an translatableOptionalFields() method to return an array with the fields as keys and the optional languages as an value as an array.
  • That's it. The package will take care of everything else.
    • There will be three tables migrated: translatable_content, translatable_translations and translatable_languages. The languages table will be filled according to the packages config.
    • A Laravel Model Observer will be registered for your model, that will hook into the data storing of your translatable fields.
    • An attribute holding the translated data will be added to your model automatically.

Options

To change the default options use

$ php artisan vendor:publish --provider="berthott\Translatable\TranslatableServiceProvider" --tag="config"
  • Inherited from laravel-targetable
    • namespace: String or array with one ore multiple namespaces that should be monitored for the configured trait. Defaults to App\Models.
    • namespace_mode: Defines the search mode for the namespaces. ClassFinder::STANDARD_MODE will only find the exact matching namespace, ClassFinder::RECURSIVE_MODE will find all subnamespaces. Defaults to ClassFinder::STANDARD_MODE.
  • Language options
  • languages: Defines the languages used in your application. Defaults to ['en' => 'English']
  • optional_languages: Defines the languages that should be treated optional. Defaults to []
  • default_language: Defines the language that should be used as default. Defaults to en

Compatibility

Tested with Laravel 10.x.

License

See License File. Copyright © 2023 Jan Bladt.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固