Welcome to SharpAPI AI Translator for Laravel Nova – the package that’s here to make your content translation smoother and smarter with the power of SharpAPI's Advanced Text Translator AI API and to leverage AI for Laravel. This package extends the already-awesome Spatie's laravel-translatable
with a Nova action you can trigger from your resource’s edit or list views.
🤖 Initiate AI Translation
can be run from either:
Here's the form you’ll use to dispatch the translation:
- Laravel: ^9.0+
- Laravel Nova: 4.0+
- PHP: 8.0+
- spatie/laravel-translatable: used for detecting translatable fields
composer require sharpapi/nova-ai-translator
You’ll need an API key from SharpAPI.com. Add it to your .env
file like so:
SHARP_API_KEY=your-sharp-api-key
Add your supported locales in config/app.php
under the locales
key:
return [
'locales' => [
'en' => 'English',
'es' => 'Spanish',
'fr' => 'French',
// Add other supported languages here
],
];
For any model you want to translate, make sure it:
- Uses Spatie’s
HasTranslations
trait. - Specifies which attributes are
translatable
. - [OPTIONAL], yet Highly Recommended: Use
Actionable
andNotifiable
traits to track actions and notifications. This ensures you can log and monitor translation progress effectively.
Example:
namespace App;
use Laravel\Nova\Actions\Actionable;
use Illuminate\Notifications\Notifiable;
use Spatie\Translatable\HasTranslations;
class BlogPost
{
use Actionable, Notifiable, HasTranslations;
protected $translatable = ['title', 'subtitle', 'content'];
}
Add the TranslateModel
action to any Nova resource, such as BlogPost
:
use SharpAPI\NovaAiTranslator\Actions\TranslateModel;
public function actions()
{
return [
(new TranslateModel())->enabled(),
];
}
The TranslateModel
action runs as a queued job, which is essential for smooth, asynchronous processing. Make sure your app’s queue is up and running for best results.
- From the resource’s edit screen, trigger the
TranslateModel
action. - A form will pop up where you can select the source and target languages and choose an optional tone.
- Note: The action checks if all target language fields already contain content. If they do, you’ll be prompted to clear these fields first if you want a fresh AI-generated translation.
- Once triggered, the action queues the job, and you can monitor its progress if your model uses the
Actionable
andNotifiable
traits.
-
Translation logs: Helpful for tracking what was translated.
-
Error handling: With
Laravel\Nova\Actions\Actionable
, you get detailed logs if something goes awry.
See CHANGELOG for recent updates.
- A2Z WEB LTD
- Dawid Makowski
- Powered by SharpAPI – your go-to for leveling up with AI in Laravel.
Licensed under the MIT License – see the License File for details.
Stay tuned for updates, tips, and tricks: