pablobae / module-simple-ai-translator
AI-powered translation module for Magento 2, enabling seamless integration with services like DeepL and ChatGPT for automated language translation. Provides configurable translation settings, language pairs, and model types for enhanced localization and multi-language store capabilities.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:magento2-module
Requires
- php: >=8.1
- magento/framework: ^103.0.0
Requires (Dev)
- phpunit/phpunit: ^9.0
README
SimpleAiTranslator is a Magento 2 extension that provides intelligent translation services by integrating with AI-powered APIs, including ChatGPT and DeepL, to offer easy and efficient multilingual content management.
Features
- ChatGPT Integration: Translate text using OpenAI's powerful ChatGPT API.
- DeepL Integration: Utilize DeepL for high-quality translation.
- Admin Configuration: Fully configurable via Magento Admin (
Stores > Configuration
). - Unit Tests: Ensures reliable performance and quality.
- Error handling and logging
- Command-line interface for translations
- Unit Tests: Ensures reliable performance and quality.
Requirements
- Magento 2.4.x
- PHP 8.1 or higher
- DeepL API key (Free or Pro) and/or ChatGPT API key
Installation
Using Composer
composer require pablobae/module-simple-ai-translator bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:clean
Manual Installation
- Create the following directory in your Magento installation:
app/code/Pablobae/SimpleAiTranslator
- Download the module and copy its contents to the above directory
- Enable the module:
bin/magento module:enable Pablobae_SimpleAiTranslator bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:clean
Configuration
Navigate to Stores > Configuration > Pablobae Extensions > Simple AI Translator
Getting API Keys
DeepL API Key
- Visit DeepL API Account
- Sign up for a DeepL API account (Free or Pro)
- Access your API key from the account dashboard
- Use api-free.deepl.com for Free API or api.deepl.com for Pro API
ChatGPT API Key
- Visit OpenAI Platform
- Create or log into your OpenAI account
- Navigate to API Keys section
- Create a new secret key
- Store the key securely as it won't be shown again
Configuration Options
General
- Enable/Disable module
- Select AI Engine (DeepL or ChatGPT)
DeepL Settings
- API Key
- API Domain (Free/Pro)
- Default languages
- Advanced translation options
ChatGPT Settings
- API Key
- Model selection
- Temperature
- Default languages
- Request timeout
Usage
Admin Panel
The extension integrates with Magento's product management interface, allowing you to:
- Translate product descriptions
- Translate product attributes
Command Line
Use the CLI command for batch translations:
bin/magento pablobae:simpleaitranslator:translate --text 'text to be translated' --language 'es'
Programmatic Usage
use Pablobae\SimpleAiTranslator\Service\Translator; class YourClass { public function __construct( private readonly Translator $translator ) {} public function translate(string $text, ?string $storeId = null): string { return $this->translator->translate($text, $storeId); } }
Supported Languages
DeepL API Languages
- English (US & UK)
- German
- French
- Spanish
- Italian
- Dutch
- Polish
- Portuguese (BR & PT)
- Russian
- Japanese
- Chinese And more...
ChatGPT Languages
ChatGPT supports a broader range of languages including:
- All major European languages
- Asian languages (Chinese, Japanese, Korean)
- Arabic
- Hindi
- African languages
- Indigenous languages And many more, as ChatGPT can understand and generate content in most world languages.
Note: While ChatGPT supports more languages, DeepL typically provides more accurate translations for its supported language pairs.
Error Handling
The extension includes comprehensive error handling for:
- Invalid/expired API keys
- Rate limits and quota exceeded
- Network timeouts
- Invalid language codes
- Malformed responses
Testing
Unit tests are provided to verify the core functionalities of the API clients (ChatGPT and DeepL). To run the tests:
- From the Magento root directory, execute:
vendor/bin/phpunit -c dev/tests/unit/phpunit.xml
Make sure you have PHPUnit installed and configured for Magento.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues and feature requests, please create an issue.
Alternatively, you can also join my Slack channel
License
This project is licensed under the GNU General Public License v3.0 or later. See the LICENSE file for details.
Credits
Developed by Pablo César Baenas Castelló (while testing AI agents) - www.pablobaenas.com