中文 | English
This guide provides a step-by-step process for setting up the eBook Translator for converting ebooks of other languages into Chinese.
Supported formats: EPUB, DOCX, SRT (subtitles). PDF format is not supported. It is recommended to convert PDF files to EPUB or DOCX format using Adobe Acrobat or similar tools before translation.
Github actions can be used to automate the translation process if your book is short and can be translated within the 6-hour time limit.
- Fork this repository.
- Go to the
Settings
tab of your forked repository. - Go to the
Secrets and variables - Actions
tab. - (Optional) If you don't have a S3 bucket, you can get free 10GB storage at Cloudflare. Go to R2 - Manage R2 API Tokens - Create API Token. Allow read and write. Take a note of the access key, secret key, and endpoint (full URL, including https://).
- Add the following secrets:
GOOGLE_API_KEY
: Your Gemini API keys.POE_API_KEY
: (Optional) Your Poe API keys.TRANSLATION_CONFIG
: (Optional) For more advanced configuration, you can provide a JSON config similar to the exampletranslation.yaml.example
file to use models other thangemini-1.5-flash
*.S3_ACCESS_KEY
: Your S3 access key.S3_SECRET_KEY
: Your S3 secret key.S3_ENDPOINT
: Your S3 bucket endpoint.
- Go to the
Variables
tab and add the following variables:CN_TITLE
: The Chinese name of the book.JP_TITLE
: The Foreign name of the book.TRANSLATION_TITLE_RETRY_COUNT
: The number of times to retry the batch translation of multiple lines (SRT / Epub title). Recommended 5 times (at least 3 times).DRYRUN
, if set toTrue
, then the translation process will be simulated without actually translating the book. Also useful if you don't want to translate rest of the book.PROMPT
: (Optional) default to "将下面的外文文本翻译为中文:"BILLING
: (Optional) If billing is enabled (set to True), the translation will not exponentially wait for a certain time on translation failure.
- Create a local folder of the name
CN_TITLE
and place the book file in the folder. Rename the file toinput.docx
,input.epub
orinput.srt
. - Create a s3 bucket
book
. Upload the folder to Cloudflare S3 bucketbook
. (ATTENTION: Keep the folder structure, don't upload the file directly to the bucket) - Go to the
Actions
tab and manually trigger the workflow. - The translated book will be available in both Chinese and bilingual formats in your S3 bucket.
- The
TRANSLATION_CONFIG
supports all google models (make sure your config entry name contains "Gemini"), all poe models (make sure your config entry name contains "Poe"), and all other models supported by LiteLLM. Note that thegemini-1.5-flash
does not need to be prefixed asgemini/gemini-1.5-flash
as in LiteLLM, unless you don't include "Gemini" in the name.
- poetry: Install using
pip install poetry
. - Python 3
Clone the repository and install the necessary dependencies:
# It is recommended to create a new virtual environment before installing the dependencies.
git clone https://github.com/ShenSheiBot/ebook-gpt-translator.git
cd ebook-gpt-translator
poetry env use python3.11
poetry install --no-root
-
Place the book file in the
output/[Chinese Book Name]/
directory and rename it toinput.docx
,input.epub
orinput.srt
-
Rename the file
.env.example
to.env
and update it with the following configurations:
CN_TITLE=[Chinese Book Name]
JP_TITLE=[Original Book Name]
TRANSLATION_TITLE_RETRY_COUNT=[Retry Count for Batch Translation of EPUB Titles or SRT Lines]
DRYRUN=[True/False, Simulate Translation]
PROMPT=[Optional, Default Prompt]
BILLING=[Optional, Enable Billing]
- Rename
translation.yaml.example
totranslation.yaml
and populate it with your Gemini API keys and Poe API keys.
{
"Gemini-Pro-api": {
"name": "gemini-pro",
"type": "api",
"retry_count": 3,
"key": "[Your Gemini API Key]"
},
"Poe-api": {
"name": "Gemini-Pro",
"type": "api",
"retry_count": 1,
"key": "[Your Poe API Key]"
}
}
-
Ensure the book file is in the
output/[Chinese Book Name]/
directory and renamed accordingly. -
Execute the following command to start the translation process:
poetry run python docxloader.py # For DOCX files
# or
poetry run python epubloader.py # For EPUB files
# or
poetry run python srtloader.py # For SRT files
The translation process can be paused and resumed. If interrupted, simply rerun the command to continue. Upon completion, the translated book will be available in both Chinese and bilingual formats in the output/[Chinese Book Name]/
directory.
Consider subscribing to the Zhihu literary critic 甚谁 for his insightful content.