Polylang Translation Preview
A WordPress plugin that provides instant Google Translate previews for selected text in the WordPress admin interface when using Polylang.
by Winners Media Limited · github.com/winnersmedia/polylang-translation-preview · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/winnersmedia/polylang-translation-preview/archive/refs/heads/main.zipA WordPress plugin that provides instant Google Translate previews for selected text in the WordPress admin interface when using Polylang.
🌟 Features
- Instant Translation Preview: Select any text in WordPress admin to see live translation tooltips
- Polylang Integration: Automatically detects page language and uses your configured Polylang languages
- Smart Language Detection: Uses actual locales (e.g.,
en_GB) instead of just language codes - HTML Formatting Preservation: Maintains bold, italic, links, and other formatting in translations
- Equivalent Language Filtering: Skips unnecessary translations between similar languages (e.g.,
en_GB↔en_CA) - Visual & Text Editor Support: Works with both TinyMCE visual editor and text areas
- Configurable Debug Logging: Optional console logging for troubleshooting
- Secure API Key Management: Built-in security best practices for Google Cloud API
📋 Requirements
- WordPress 5.0 or higher
- PHP 7.4 or higher
- Polylang plugin (free or pro)
- Google Cloud Translation API key
🚀 Installation
From GitHub
- Download the latest release or clone this repository
- Upload the
polylang-translation-previewfolder to/wp-content/plugins/ - Activate the plugin through the WordPress admin
- Configure your settings at Settings → Translation Preview
Manual Installation
cd wp-content/plugins/
git clone https://github.com/your-username/polylang-translation-preview.git
⚙️ Configuration
1. Get Google Cloud Translation API Key
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable the Cloud Translation API:
- Navigate to APIs & Services → Library
- Search for "Cloud Translation API"
- Click and press Enable
- Create credentials:
- Go to APIs & Services → Credentials
- Click Create Credentials → API Key
- Copy the generated API key
- Security (Recommended): Restrict your API key:
- Click on your API key in Credentials
- Under "API restrictions", select "Restrict key"
- Choose "Cloud Translation API" only
- Under "Website restrictions", add your domain
- Set up billing (required for Translation API)
2. Configure Plugin Settings
- Go to Settings → Translation Preview in WordPress admin
- Enter your Google Cloud API key
- Select your default target language from your Polylang languages
- Optionally enable debug logging for troubleshooting
💡 Usage
- Edit any post, page, or term in WordPress admin
- Select text in the editor or text fields
- View instant translation in the popup tooltip
- Formatted content (bold, italic, links) is preserved in translations
Supported Content Areas
- TinyMCE Visual Editor
- Text Editor/HTML mode
- Text input fields
- Textarea fields
- Custom field inputs
🎯 Smart Features
Language Equivalence Detection
The plugin intelligently skips translations between equivalent language variants:
- ✅
en_GB→fr_FR(English to French) - Translates - ❌
en_GB→en_CA(UK English to Canadian English) - Skips with message - ❌
de_DE→de_CH(German Germany to German Switzerland) - Skips with message
HTML Preservation
Maintains formatting in translations:
- Bold and italic text
- Links with URLs
- Lists and paragraphs
- Headings and blockquotes
🔧 Developer Features
Debug Logging
Enable detailed logging in settings to troubleshoot:
- Translation API requests/responses
- Language detection process
- Selection coordinates
- TinyMCE editor events
Hooks & Filters
Currently no custom hooks available, but pull requests welcome!
💰 Pricing
Google Cloud Translation API pricing:
- Free Tier: 500,000 characters per month
- Paid Usage: $20 per 1M characters
- Billing account required but free tier available
🛠️ Troubleshooting
Common Issues
-
No translation tooltip appearing
- Check API key is correctly entered
- Verify Google Cloud billing is set up
- Enable debug logging and check browser console
-
"Equivalent language variants" message
- This is normal for same-language variants (e.g.,
en_GB↔en_CA) - Check your Polylang language configuration
- This is normal for same-language variants (e.g.,
-
Escaped characters (e.g., "it\'s")
- This should be fixed in current version
- Enable debug logging to troubleshoot
Debug Mode
Enable debug logging in Settings → Translation Preview to see detailed console logs for troubleshooting.
🤝 Contributing
We welcome contributions! Please feel free to submit pull requests or open issues.
Development Setup
- Clone the repository
- Install in WordPress development environment
- Enable debug logging for development
- Make changes and test thoroughly
📝 Changelog
Version 1.0.0
- Initial release
- Google Translate integration
- Polylang language detection
- HTML formatting preservation
- Smart language equivalence detection
- Debug logging controls
- Comprehensive setup instructions
📄 License
This plugin is licensed under the GPL v3 or later.
🏢 About Winners Media Limited
This plugin is created and maintained by Winners Media Limited, a digital agency specializing in WordPress development and digital solutions.
- Website: winnersmedia.co.uk
- Contact: For support or custom development inquiries
🔗 Links
⭐ Support
If you find this plugin helpful, please consider:
- ⭐ Starring this repository
- 🐛 Reporting issues
- 💡 Suggesting new features
- 🤝 Contributing code improvements
Made with ❤️ by Winners Media Limited