Nov 11, 2024
Photo by Cherry Lin on Unsplash
Enter the SharpAPI AI Translator for Laravel Nova. This package seamlessly plugs AI-powered translation directly into your Nova dashboard, eliminating repetitive translation tasks and freeing you up to focus on the good stuff.
Want to see all the package details? Head over to GitHub: https://github.com/sharpapi/nova-ai-translator
If you're using
spatie/laravel-translatable
then we also assume you're already using and know how to configure their https://github.com/spatie/nova-translatable
In a nutshell, it combines the Spatie’s laravel-translatable package with the superpowers of SharpAPI’s AI, transforming those content fields in your app into effortlessly translatable assets. The result? A new action on your Nova dashboard called 🤖 Initiate AI Translation that takes care of the translation work for you.
From the Nova resources list or the edit screen, you can queue up translations between any configured languages directly in Nova, with the AI taking over as soon as you hit the button. Need to translate a blog post from English to Spanish? It’s handled.
If you're a Laravel Nova user managing content in multiple languages, this package is for you. It’s ideal for teams that regularly work with internationalized apps and need content quickly translated without manually flipping through Google Translate. Imagine all that time saved when your content auto-magically translates itself right from Nova!
Make sure you’re running:
You’ll also need an account at SharpAPI.com for API access, but we’ll get to that.
composer require sharpapi/nova-ai-translator
Add your API key from SharpAPI to your .env
:
SHARP_API_KEY=your-sharp-api-key
Define your locales in config/app.php
under the locales
key:
return [
'locales' => [
'en' => 'English',
'es' => 'Spanish',
'fr' => 'French',
// Add any other languages your app needs
],
];
Your translatable models should use:
HasTranslations
trait from Spatie.Actionable
and Notifiable
traits to track actions.Here’s a quick setup for, say, a BlogPost
model:
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'];
}
Hook the TranslateModel
action into your Nova resource by adding it to the actions array:
use SharpAPI\NovaAiTranslator\Actions\TranslateModel;
public function actions()
{
return [
(new TranslateModel())->enabled(),
];
}
This action uses a queue to handle translations asynchronously, so make sure your queue is ready to go.
Once integrated, the action lives right in your Nova resource. Here’s how it works:
Open the action either from the resources list or from the edit view of any resource.
Example: Triggering the Action from the Edit View
A form lets you pick the source and target languages and even set the tone. You’ll also see a list of fields that will be translated, so there are no surprises.
Once you confirm, the action checks if the target fields are already populated. If they are, it gently suggests that you clear them before proceeding. Assuming all systems are go, it queues the translation job. You can even keep an eye on it if you’re using the Actionable
and Notifiable
traits.
Nova’s action log feature helps track the translations. This is handy if you need to debug any issues or just like seeing AI in action.
Example: Translation Log in Action
Example: Error Handling (if it goes sideways)
spatie/laravel-translatable
, you get the best of both worlds: structured localization with the muscle of an AI translation.With SharpAPI AI Translator for Laravel Nova, your app’s translation game just got a massive upgrade with its new Laravel AI capabilities.. Give it a spin, and let us know how it works for you!