Skip to content

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

🌐 OpenAI Translator

Seamless language translation powered by OpenAI and Google Translate

Python OpenAI Telegram License


📋 Table of Contents


🎯 Overview

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.


✨ Features

  • 🤖 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

📦 Installation

  1. Clone the repository

    git clone https://github.com/mk23rd/OpenAI_Translator.git
    cd OpenAI_Translator
  2. 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

⚙️ Configuration

OpenAI API Setup

  1. Obtain your OpenAI API key from OpenAI Platform
  2. Update Translate_ai.py with your API key:
    openai.api_key = 'your-api-key-here'

Telegram Bot Setup

  1. Create a Telegram bot via @BotFather
  2. Copy the bot token
  3. Update Translate_bot.py with your bot token:
    bot = telegram.Bot(token="your-bot-token-here")
    updater = Updater(token="your-bot-token-here", use_context=True)

Google Cloud Translation Setup

  1. Set up a Google Cloud project and enable the Translation API
  2. Configure authentication credentials as per Google Cloud documentation

🚀 Usage

CLI Translation

Run the command-line translator:

python Translate_ai.py

Follow the prompts:

  1. Enter the text you want to translate
  2. Enter the target language code (e.g., fr for French, es for Spanish)
  3. 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?

Telegram Bot

Run the Telegram bot:

python Translate_bot.py

Once running, interact with your bot on Telegram using the available commands.


🤖 Bot 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

📚 Requirements

  • Python 3.7 or higher
  • OpenAI API key
  • Google Cloud Translation API credentials
  • Telegram Bot Token (for bot functionality)

Python Packages:

  • openai - OpenAI API client
  • googletrans==4.0.0rc1 - Google Translate API
  • python-telegram-bot - Telegram bot framework
  • google-cloud-translate - Google Cloud Translation API

🤝 Contributing

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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

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!

About

Integrating OpenAI to translate any language

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages