A Payload CMS plugin that provides AI-powered content translation using OpenAI, designed to work seamlessly with Payload's built-in localization system.
- Leverages Existing Localization: Works with the languages you've already configured in your Payload localization settings
- Context-Aware UI: Adds an "Auto-Translate" button that appears alongside any localized field when you are viewing a non-primary language
- One-Click Translations: With a single click, the system fetches the content from the document's main language and translates it to the current locale
- Smart Field Detection: Only shows translation buttons on fields you've configured for translation
- Multiple Field Types: Supports text, textarea, and rich text fields
npm install payload-plugin-ai-localization
First, ensure your Payload config has localization enabled:
import { buildConfig } from 'payload'
import { aiLocalization } from 'payload-plugin-ai-localization'
export default buildConfig({
// ... other config
localization: {
locales: ['en', 'de', 'fr', 'es'], // Configure your supported locales
defaultLocale: 'en', // Set your default locale
},
plugins: [
aiLocalization({
openai: {
apiKey: process.env.OPENAI_API_KEY, // Your OpenAI API key
model: 'gpt-4.1-nano', // Optional: specify the model (defaults to gpt-4.1-nano)
},
collections: {
posts: {
fields: ['title', 'excerpt', 'content'], // Fields that should have auto-translate buttons
},
pages: {
fields: ['title', 'description'],
},
},
}),
],
})
- Create or edit a document in your Payload admin panel
- Switch to a non-primary language using Payload's built-in language switcher
- Click the "Auto-translate from English" button that appears below any configured field
- The content will be automatically translated from the primary language to the current locale
Make sure to set your OpenAI API key in your environment variables of PayloadCMS:
OPENAI_API_KEY=your_openai_api_key_here
The plugin integrates with Payload's native localization system by:
- Detecting the current locale from Payload's context
- Fetching content from the primary locale when you click translate
- Using OpenAI to translate the content to the target language
- Updating the field in the current locale with the translated content
text
- Single line text fieldstextarea
- Multi-line text fieldsrichText
- Rich text editor fields (preserves formatting)
The plugin adds these endpoints to your Payload app:
POST /api/ai-localization/translate-bulk
- Translates content between locales
MIT
Contributions are welcome! Please read the contributing guidelines before submitting PRs.
For issues and questions:
- Create an issue on GitHub
- Check the Payload CMS Discord community
- Review the documentation
Note: This plugin requires Payload CMS v3.37.0 or higher and an OpenAI API key.