Skip to content

artwalker/EasyTranslator

Repository files navigation

EasyTranslator

    Easy Translator

   Your Companion for Multilingual Reading

English badge简体中文 badgex badgeyoutube badgebilibili badge

Buy Me A Coffee


📑 Introduction

A command-line tool crafted with the OpenAI API, supporting translation for various file formats, including .txt, .pdf, .docx, .md, .mobi, and .epub.
Effortlessly translate your text files, eliminating language barriers with ease.

🔔 Prerequisites

🐍 Code Section
git clone https://github.com/artwalker/EasyTranslator.git
pip install -r preconditions.txt
📜 Configuration Files
  • .env

    • Follow the instructions here to get your OpenAI API key

    • OPENAI_API_KEY: Specify the OpenAI API Key, can use multiple keys, format like "sk-xxxxxxx, sk-xxxxxxx"

    • GPT_MODEL: Specify the model to be used, for example, "gpt-3.5-turbo"

    • GPT_TEMPERATURE: Specify the randomness of the model's responses, it's advisable to set it to 0 for text translation.

    • If using OpenAI API provided by Azure, the following parameters need to be set:

    • OPENAI_API_MODEL_AZURE: Deployment name on Azure

    • OPENAI_API_KEY_AZURE: Specify the key for Azure OpenAI API

    • OPENAI_API_ENDPOINT_AZURE: Endpoint of the API

    • OPENAI_API_VERSION_AZURE: Version of the API

  • settings.cfg:

    • openai-proxy: Proxy for OpenAI

    • language: Language for translation

    • prompt: Input prompt for specified model translation

    • bilingual-output: Whether to save as bilingual text

    • langcode: Language code for generated epub files

    • startpage: Starting page for specified pdf file

    • endpage: Ending page for specified pdf file

    • transliteration-list: Transliteration list file name

    • transliteration-word-capi-low: Whether the transliteration list is case-sensitive

🏃 Usage

python easy_translator.py filename [--show] [--tlist] [--azure] [--test]
python translate_all.py

Please add a period at the position in the .md document where there is no ending punctuation mark

👏 Explanation
  • filename: Specify the name of the file to be translated, supports txt, pdf, docx, epub, mobi formats

  • --show: Display the translation process of the text

  • --tlist: Use a transliteration list

  • --azure: Use Azure to call the OpenAI API

  • --test: Used to test the translation effect, translates three paragraphs of text, typically used for debugging

  • translate_all.py: Use the script translate_all.py to batch translate text

    • First, make sure that the file names are in the format of 01_filea.txt, 02_fileb.txt, etc., with a sorting prefix added before each file name

    • Second, place the text you want to translate in the book directory. You can modify this directory in the source code if needed

📌 Example
python easy_translator.py ./book/profile.txt
python easy_translator.py ./book/profile.txt --show
python easy_translator.py ./book/profile.txt --azure
python easy_translator.py ./book/profile.txt --azure --show
python easy_translator.py ./book/profile.txt --show --tlist
python easy_translator.py ./book/profile.txt --show --tlist --azure
python easy_translator.py ./book/profile.txt --show --tlist --azure --test

use terminal in one file location to save the project
Choose a directory and clone the project using the terminal

enter the file by cloned
Enter the directory of the cloned project

configure key
Configure OpenAI's key

open terminal in current file
Open the terminal in the current directory

run pip command
Run the pip command

begin to translation happily
Start the translation journey happily

💝 Reward

If you feel that this program has awakened your soul like a cup of hot coffee or solved your problems like a Swiss army knife, you might consider showing your appreciation with a reward;

Just like tipping a barista, your contribution will fuel my motivation to improve this program and create new code, making the world a better place;

Regardless of the amount you choose to reward, I will be delighted, as if receiving a gift;

Thank you for your generous support!

Alipay WeChat

Star History Chart

About

Your Companion for Multilingual Reading

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages