OpenAI Translator is a powerful translation tool that combines the capabilities of OpenAI's language models with Google Translate to provide accurate and context-aware translations. The project includes both a command-line interface and a fully-featured Telegram bot for easy access to translation services.
- 🤖 Dual Translation Engine: Leverages both OpenAI and Google Translate APIs
- 💬 Telegram Bot Integration: Translate on-the-go via Telegram
- 🔍 Language Detection: Automatically detect the source language
- 👤 User Preferences: Save preferred translation languages
- 🌍 Multi-Language Support: Translate between numerous languages
- ⚡ Real-time Translation: Get instant translation results
-
Clone the repository
git clone https://github.com/mk23rd/OpenAI_Translator.git cd OpenAI_Translator -
Install required packages
pip install openai pip install googletrans==4.0.0rc1 pip install python-telegram-bot pip install google-cloud-translate
Or use pip with all dependencies at once:
pip install openai googletrans==4.0.0rc1 python-telegram-bot google-cloud-translate
- Obtain your OpenAI API key from OpenAI Platform
- Update
Translate_ai.pywith your API key:openai.api_key = 'your-api-key-here'
- Create a Telegram bot via @BotFather
- Copy the bot token
- Update
Translate_bot.pywith your bot token:bot = telegram.Bot(token="your-bot-token-here") updater = Updater(token="your-bot-token-here", use_context=True)
- Set up a Google Cloud project and enable the Translation API
- Configure authentication credentials as per Google Cloud documentation
Run the command-line translator:
python Translate_ai.pyFollow the prompts:
- Enter the text you want to translate
- Enter the target language code (e.g.,
frfor French,esfor Spanish) - Get your translated text!
Example:
Enter text to translate: Hello, how are you?
Enter target language code (e.g., 'fr' for French): es
Translated text: Hola, ¿cómo estás?
Run the Telegram bot:
python Translate_bot.pyOnce running, interact with your bot on Telegram using the available commands.
| Command | Description | Usage |
|---|---|---|
/start |
Initialize the bot and get a welcome message | /start |
/lang |
Set your preferred translation language | /lang spanish |
/checklang |
Check your current language preference | /checklang |
/translate |
Translate text to your preferred language | /translate Hello world |
/check |
Detect the language of given text | /check Bonjour |
Example Bot Workflow:
User: /start
Bot: WELCOME John
User: /lang french
Bot: FRENCH set for John
User: /translate Good morning
Bot: TRANSLATED TEXT: Bonjour
User: /check Hola
Bot: Detected language: SPANISH Confidence: 0.99
- Python 3.7 or higher
- OpenAI API key
- Google Cloud Translation API credentials
- Telegram Bot Token (for bot functionality)
Python Packages:
openai- OpenAI API clientgoogletrans==4.0.0rc1- Google Translate APIpython-telegram-bot- Telegram bot frameworkgoogle-cloud-translate- Google Cloud Translation API
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by mk23rd
⭐ Star this repository if you find it helpful!