定制 yamanhacioglu/laravel-auto-translate 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

yamanhacioglu/laravel-auto-translate

Composer 安装命令:

composer require yamanhacioglu/laravel-auto-translate

包简介

Automatic translation package for Laravel models using DeepL

README 文档

README

Automatic translation package for Laravel models using DeepL API.

{{ THIS PACKAGE STILL IN TEST PROCESS. }}

Installation

composer require northlab/laravel-auto-translate

Configuration

  1. Publish the configuration and migrations:
php artisan vendor:publish --provider="NorthLab\AutoTranslate\AutoTranslateServiceProvider"
  1. Run the migrations
php artisan migrate
  1. Add your DeepL API key to your new model (Deepl):

Usage

  1. Implement the Translatable interface and use the HasAutoTranslations trait in your model:
use NorthLab\AutoTranslate\Contracts\Translatable;
use NorthLab\AutoTranslate\Traits\HasAutoTranslations;

For Laravel 11

#[ObservedBy([TranslatableModelObserver::class])]
class Post extends Model implements Translatable
{
    use HasAutoTranslations;

    protected array $translatable = ['title', 'content'];

    protected string $sourceLanguage = 'Column containing source language'

    public function getTranslatableAttributes(): array
    {
        return $this->translatable;
    }

    public function getSourceLanguageAttribute(): string
    {
        return $this->source_language;
    }

}

For Laravel 10 ...

class Post extends Model implements Translatable
{
    use HasAutoTranslations;

    protected array $translatable = ['title', 'content'];

    protected string $sourceLanguage = 'Column containing source language'

    public function getTranslatableAttributes(): array
    {
        return $this->translatable;
    }

    public function getSourceLanguageAttribute(): string
    {
        return $this->source_language;
    }

    protected static function boot()
    {
       Post::observe(TranslatableModelObserver::class);
    }
}
  1. The translations will be automatically processed when the model is saved.

  2. Skip translation:

$post->withoutAutoTranslation()->save();
  1. Updates

It will be constantly updated, taking into account its dependencies and features that can be added.

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-11