yamanhacioglu / laravel-auto-translate
Automatic translation package for Laravel models using DeepL
dev-main
2024-10-11 23:42 UTC
Requires
- php: ^8.2
- deeplcom/deepl-php: ^1.9
- illuminate/support: ^9|^10|^11
- mcamara/laravel-localization: ^2.0
- spatie/laravel-translatable: ^6.8
Requires (Dev)
- orchestra/testbench: ^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.0|^10.0
This package is auto-updated.
Last update: 2024-12-12 00:01:11 UTC
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.