laravel-auto-translate maintained by yamanhacioglu
Description
Automatic translation package for Laravel models using DeepL
Author
Last update
2024/10/12 01:42
(dev-main)
License
Downloads
1
Laravel Auto Translate
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.