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
- Publish the configuration and migrations:
php artisan vendor:publish --provider="NorthLab\AutoTranslate\AutoTranslateServiceProvider"
- Run the migrations
php artisan migrate
- Add your DeepL API key to your new model (Deepl):
Usage
- 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); } }
-
The translations will be automatically processed when the model is saved.
-
Skip translation:
$post->withoutAutoTranslation()->save();
- 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
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-11