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. Details at https://github.com/sharpapi/nova-ai-translator
# 1. Install the package via Composer
composer require sharpapi/nova-ai-translator
# 2. API Key Configuration
# You’ll need an API key from SharpAPI.com. Add it to your .env file like so:
SHARP_API_KEY=your-sharp-api-key
# 3. Supported Locales Configuration
# 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
],
];
# 4. Add to Nova Resource Models
# 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 and Notifiable traits to track actions and notifications. This ensures you can log and monitor translation progress effectively.
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'];
}
# 5. Attach the Action in a Nova Resource
# Add the TranslateModel action to any Nova resource, such as BlogPost:
use SharpAPI\NovaAiTranslator\Actions\TranslateModel;
public function actions()
{
return [
(new TranslateModel())->enabled(),
];
}
# Voila!