victormgomes / auto-translate
Automatic translation for translatable attributes in Eloquent models
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/bus: ^11.0||^12.0||^13.0
- illuminate/cache: ^11.0||^12.0||^13.0
- illuminate/contracts: ^11.0||^12.0||^13.0
- illuminate/database: ^11.0||^12.0||^13.0
- illuminate/http: ^11.0||^12.0||^13.0
- illuminate/queue: ^11.0||^12.0||^13.0
- illuminate/support: ^11.0||^12.0||^13.0
- spatie/laravel-package-tools: ^1.16
- victormgomes/translator: dev-main
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- spatie/laravel-ray: ^1.35
README
Automatic translation for translatable attributes in Eloquent models
Introduction
Auto Translate is a powerful addon for spatie/laravel-translatable that automates the translation of your model attributes. It listens for model saving events and automatically translates your content into multiple languages using configured translation providers.
Why use this package?
- Automation: Save time by letting the package handle translations automatically upon saving models.
- Seamless Integration: Built specifically to work with the industry-standard
spatie/laravel-translatable. - Declarative Configuration: Use PHP attributes to define which fields should be translated, keeping your models clean and readable.
- Scalable: Easily manage multi-language content across your entire application without manual intervention.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by sponsoring us on GitHub.
Installation
You can install the package via composer:
composer require victormgomes/auto-translate
You can publish and run the migrations with:
php artisan vendor:publish --tag="auto-translate-migrations"
php artisan migrate
Usage
Simply use the AutoTranslatable trait and the #[AutoTranslate] attribute on your models. Specify which fields should be automatically translated.
use Victormgomes\AutoTranslate\Concerns\AutoTranslatable; use Victormgomes\AutoTranslate\AutoTranslate; use Spatie\Translatable\HasTranslations; #[AutoTranslate(fields: ['name'])] class Category extends Model { use AutoTranslatable, HasTranslations; public $translatable = ['name']; }
When you save the Category model, the name attribute will be automatically translated into all supported locales defined in your configuration.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.