Giter Club home page Giter Club logo

teletrans's Introduction

TeleTrans - The Telegram Translator

TeleTrans is a Python-based Telegram bot that translates messages in real-time. It uses the OpenAI API and DeepL API for translation.

Warning

This project requires the use of Telegram Apps API, which is a high-risk operation that could easily lead to a ban of your account. Please make sure you read and understand the Telegram API Terms of Service before using this project.

Features

  • Real-time translation of messages.
  • Supports multiple languages.
  • Uses OpenAI and DeepL for translation.
  • Configurable source and target languages.
  • Command mode for enabling/disabling translation and setting languages.

Requirements

  • Python 3.10+
  • aiohttp
  • telethon
  • requests

Manual Installation

Click for manual install details

Install & Setup & Run

  1. Clone the repository:

    git clone https://github.com/ihategfw/teletrans.git
  2. Navigate to the project directory:

    cd teletrans
  3. Install the required Python packages:

    pip install -r requirements.txt
  4. Create a config.json file in the project directory:

    {
        "api_id": "your_telegram_api_id",
        "api_hash": "your_telegram_api_hash",
        "target_config": {},
        "openai": {
            "enable": true,
            "api_key": "your_openai_api_key",
            "url": "https://api.openai.com/v1/chat/completions",
            "model": "gpt-3.5-turbo"
        }
    }
    • api_id and api_hash are required for the Telegram API. You can get them by creating a new application at my.telegram.org.
    • If openai.enable is set to true, the bot will use the OpenAI API to translate, and this is only effective when the target language is English.
  5. Run the script with an optional argument to specify the working directory:

    python teletrans.py </path/to/your/directory>

    If no directory is specified, the script will run in the current directory.

Running as a Daemon

  1. Create a new service file:

    sudo nano /etc/systemd/system/teletrans.service
  2. Add the following content to the file:

    [Unit]
    Description=TeleTrans
    After=network.target
    
    [Service]
    Type=simple
    WorkingDirectory=/path/to/teletrans
    ExecStart=/usr/bin/python3 /path/to/teletrans/teletrans.py /path/to/your/directory
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target

    Replace /path/to/teletrans with the path to the project directory. /path/to/your/directory is the directory where the bot will store the configuration and logs.

  3. Start the service and enable it to run on boot:

    sudo systemctl start teletrans
    sudo systemctl enable teletrans
  4. Check the status of the service:

    sudo systemctl status teletrans
  5. To stop the service, use:

    sudo systemctl stop teletrans

Installation with Docker

Click for Docker install details
  1. Install Docker:

    bash <(curl -sSL https://get.docker.com)
  2. Make a directory for the bot:

    mkdir teletrans
    cd teletrans
  3. Create a config.json file in the project directory:

    {
        "api_id": "your_telegram_api_id",
        "api_hash": "your_telegram_api_hash",
        "target_config": {},
        "openai": {
            "enable": true,
            "api_key": "your_openai_api_key",
            "url": "https://api.openai.com/v1/chat/completions",
            "model": "gpt-3.5-turbo"
        }
    }
    • api_id and api_hash are required for the Telegram API. You can get them by creating a new application at my.telegram.org.
    • If openai.enable is set to true, the bot will use the OpenAI API to translate, and this is only effective when the target language is English.
  4. Run the bot with Docker:

    docker run -itd --name teletrans -v $(pwd):/app/config --restart=unless-stopped ghcr.io/ihategfw/teletrans:latest
  5. For the first time, you need to execute the following command to log in to your Telegram account:

    docker exec -it teletrans python teletrans.py /app/config

    Follow the instructions to log in.

    After logging in, please stop the container by pressing Ctrl+C and restart it:

    docker restart teletrans

Usage

Click for usage details
  1. To enable translation from Chinese to English and Japanese, and keep the original message, use the following command in the chat:

    .tt-on,zh,zh|en|ja
    

    The code of languages supported by DeepL API can be found here.

  2. To disable translation in the chat, simply use:

    .tt-off
    
  3. To enable or disable global translation, use the following command:

    .tt-on-global,zh,zh|en|ja
    .tt-off-global
    
    • The chat config is prioritized over the global config.
  4. If you want to send a message without translating it, use the .tt-skip command followed by your message:

    .tt-skip Hello, this message will not be translated.
    
  5. If you want to translate only this message once, use the following command, making sure to separate the command and the text with a space; this command ignores the .tt-on or .tt-on-global parameter:

    .tt-once,en,en|zh Hello, I am teletrans bot
    
  6. Edited message is not translated by default. If you need to translate it, insert .tt at the beginning of the message.

    .tt This edited message will be translated.
    
  7. If you want to translate the message you replied to, use the below command:

    .tt,zh,zh|en|ja
    

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MPL-2.0 License - see the LICENSE file for details.

teletrans's People

Contributors

ihategfw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

teletrans's Issues

DeepLX URL 可能需要移到配置文件里了

https://api.deeplx.org 1.2k

前几天我的deeplx被一个老六开着代理日刷百万次,我直接放弃更新。不过看很多佬友期待的眼神,还是给它复活了。

现在我为它加了 LINUX DO Connect 认证,用以杜绝被刷。最新的接口地址是:

https://api.deeplx.org/< api-key >/translate

每个人的地址都是不同的,这个 请去 https://connect.linux.do 3.1k 获取,就是那一串 DeepLX Api Key 的字符串 。

https://linux.do/t/topic/111737/37

消息带有 emoji 无法被翻译

源信息:https://t.me/durov/264 转发至个人收藏,然后回复这条信息 .tt,en,en|zh 结果就是没反应无法翻译,不论用不用 openai 都会这样。且日志里没有 翻译从 xx 至 xx 耗时,我才没有正确解析?

2024-04-22 11:35:24,909 - INFO - Reply message: 295066
2024-04-22 11:35:25,066 - INFO - 翻译消息: .tt,en,en|zh
2024-04-22 11:35:25,066 - INFO - 翻译耗时: 1.3828277587890625e-05

Adding translation to portuguese in documentation

I've been looking for a project to start making a documentation in portuguese, so I've found this repository and I had a interest on working with it.

Is there any chance to contribuite it with a portuguese documentation?

搭配 deepseek 用似乎无法中译英

.tt-once,zh,zh|en 不过我们这边异地首办应该是可以的,我同学都办过
2024-05-29 13:19:46,152 - INFO - 翻译消息: 不过我们这边异地首办应该是可以的,我同学都办过
2024-05-29 13:19:48,365 - INFO - 翻译从 zh 至 en 耗时: 2.211108922958374
2024-05-29 13:19:48,366 - INFO - 翻译耗时: 2.2134783267974854

结果是原文返回,没有成功翻译到英文

image image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.