{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"bilingual book maker","text":"
The bilingual_book_maker
is an AI translation tool that uses ChatGPT to assist users in creating multi-language versions of epub/txt files and books.
This tool is exclusively designed for translating epub books that have entered the public domain and is not intended for copyrighted works. Before using this tool, please review the project's disclaimer.
"},{"location":"book_source/","title":"Translate from Different Sources","text":""},{"location":"book_source/#txtsrt","title":"txt/srt","text":"Txt files and srt files are plain text files. This program can translate plain text.
python3 make_book.py --book_name test_books/the_little_prince.txt --test --language zh-hans\n
"},{"location":"book_source/#epub","title":"epub","text":"epub is made of html files. By default, we only translate contents in <p>
. Use --translate-tags
to specify tags need for translation. Use comma to separate multiple tags. For example: --translate-tags h1,h2,h3,p,div
bbook_maker --book_name test_books/animal_farm.epub --openai_key ${openai_key} --translate-tags div,p\n
If you want to translate strings in an e-book that aren't labeled with any tags, you can use the --allow_navigable_strings
parameter. This will add the strings to the translation queue. Note that it's best to look for e-books that are more standardized if possible.
Use --book_from
option to specify e-reader type (Now only kobo
is available), and use --device_path
to specify the mounting point.
# Translate books download from Rakuten Kobo on kobo e-reader\nbbook_maker --book_from kobo --device_path /tmp/kobo\n
"},{"location":"cmd/","title":"Command Line Options","text":""},{"location":"cmd/#test-translate","title":"Test translate","text":"--test
Use this option to preview the result if you haven't paid for the service or just want to test. Note that there is a limit and it may take some time.
bbook_maker --book_name test_books/Lex_Fridman_episode_322.srt --openai_key ${openai_key} --test\n
bbook_maker --book_name test_books/animal_farm.epub --openai_key ${openai_key} --test --language zh-hans\n
--test_num <TEST_NUM>
Use this option to set how many paragraph you want to translate for testing. Default is 10.
"},{"location":"cmd/#resume","title":"Resume","text":"--resume
Use this option to manually resume the process after an interruption.
"},{"location":"cmd/#retranslate-epub-only","title":"Retranslate (epub only)","text":"--retranslate <translated_filepath, file_name_in_epub, start_str [, end_str]>
If a file in epub is not translated well, it supports to re-translate part of epub separately.
This option take 4 arguments: translated_filepath
, file_name_in_epub
, start_str
, end_str
. end_str
is optional.
Retranslate from start_str to end_str's tag:
bbook_maker --book_name \"test_books/animal_farm.epub\" --retranslate 'test_books/animal_farm_bilingual.epub' 'index_split_002.html' 'in spite of the present book shortage which' 'This kind of thing is not a good symptom. Obviously'\n
Retranslate start_str's tag:
bbook_maker --book_name \"test_books/animal_farm.epub\" --retranslate 'test_books/animal_farm_bilingual.epub' 'index_split_002.html' 'in spite of the present book shortage which'\n
Retranslate start_str's tag, auto find filename:
bbook_maker --book_name \"test_books/animal_farm.epub\" --retranslate 'test_books/animal_farm_bilingual.epub' '' 'in spite of the present book shortage which'\n
Warning:
It deletes from the tag at start_str of the finished book to the next tag at end_str, and then re-translates.
Therefore, please make sure that the next tag of end_str is the translated content. (If end_str is not provided, the next label of start_str is guaranteed to be the translated content.) There can be missing translations between the two strings, but if end_str is not translated, there will be problems.
"},{"location":"cmd/#customize-output-style-epub-only","title":"Customize output style (epub only)","text":"--translation_style <TRANSLATION_STYLE>
Support changing the output style of epub files.
bbook_maker --book_name test_books/animal_farm.epub --translation_style \"color: #4a4a4a; font-style: normal; background-color: #f7f7f7; padding: 5px; margin: 10px 0; border-radius: 5px;\"\n
"},{"location":"cmd/#proxy","title":"Proxy","text":"--proxy <PROXY>
Use this option to specify proxy server for internet access. Enter a string such as http://127.0.0.1:7890
.
--api_base <API_BASE_URL>
If you want to change api_base like using Cloudflare Workers, use this option to support it.
bbook_maker --book_name 'animal_farm.epub' --openai_key sk-XXXXX --api_base 'https://xxxxx/v1'\n
Note: the api url should be 'https://xxxx/v1
'. Quotation marks are required.
--api_base <API_BASE_URL>
--deployment_id <DEPLOYMENT_ID>
You can use the api endpoint provided from Microsoft.
bbook_maker --book_name 'animal_farm.epub' --openai_key XXXXX --api_base 'https://example-endpoint.openai.azure.com' --deployment_id 'deployment-name'\n
Note : Current only support chatgptapi model for deployment_id. And api_base
must be provided when using deployment_id
. You can check here for more information about deployment_id
.
--batch_size
Use this parameter to specify the number of lines for batch translation. Default is 10. (Currently only effective for txt files).
python3 make_book.py --book_name test_books/the_little_prince.txt --test --batch_size 20\n
"},{"location":"cmd/#accumulated-num","title":"Accumulated Num","text":"--accumulated_num <ACCUMULATED_NUM>
Wait for how many tokens have been accumulated before starting the translation. gpt3.5 limits the total_token to 4090.
For example, if you use --accumulated_num 1600, maybe openai will output 2200 tokens and maybe 200 tokens for other messages in the system messages user messages. 1600+2200+200=4000, so you are close to the limit.
You have to choose your own value, there is no way to tell if the limit is reached before sending request.
"},{"location":"disclaimer/","title":"Disclaimer","text":"If you have any concerns or suggestions about the use of this project, please contact us through the issues section.
\u514d\u8d23\u58f0\u660e\uff1a
\u5982\u679c\u60a8\u5bf9\u8be5\u9879\u76ee\u7684\u4f7f\u7528\u6709\u4efb\u4f55\u7591\u8651\u6216\u5efa\u8bae\uff0c\u8bf7\u901a\u8fc7 issues \u4e0e\u6211\u4eec\u8054\u7cfb\u3002
"},{"location":"env_settings/","title":"Environment Settings","text":"You can also write information into env to skip some options.
"},{"location":"env_settings/#model-keys","title":"Model keys","text":"# Set env BBM_OPENAI_API_KEY to ignore option --openai_key\nexport BBM_OPENAI_API_KEY=${your_api_key}\n\n# Set env BBM_CAIYUN_API_KEY to ignore option --caiyun_key\nexport BBM_CAIYUN_API_KEY=${your_api_key}\n
"},{"location":"installation/","title":"Installation","text":""},{"location":"installation/#pip","title":"pip","text":"bilingual_book_maker has been published as a Python package and can be install by pip
. (Recommend in a virtual environment.)
pip install -U bbook_maker\n
"},{"location":"installation/#git","title":"git","text":"You can also install from github if you want to use the latest version.
git clone git@github.com:yihong0618/bilingual_book_maker.git\npip install .\n
"},{"location":"model_lang/","title":"Model and Languages","text":""},{"location":"model_lang/#models","title":"Models","text":"-m, --model <Model>
Currently bbook_maker
supports these models: chatgptapi
, gpt3
, google
, caiyun
, deepl
, deeplfree
, gpt4
, gpt4omini
, o1-preview
, o1
, o1-mini
, o3-mini
, claude
, customapi
. Default model is chatgptapi
.
There are three models you can choose from.
gpt3
bbook_maker --book_name test_books/animal_farm.epub --model gpt3 --openai_key ${openai_key}\n
chatgpiapi
chatgptapi
is GPT-3.5-turbo, which is used by ChatGPT currently.
bbook_maker --book_name test_books/animal_farm.epub --model chatgptapi --openai_key ${openai_key}\n
gpt4
bbook_maker --book_name test_books/animal_farm.epub --model gpt4 --openai_key ${openai_key}\n
If using gpt4
, you can add --use_context
to add a context paragraph to each passage sent to the model for translation.
bbook_maker --book_name test_books/animal_farm.epub --model gpt4 --openai_key ${openai_key} --use_context\n
The option --use_context
prompts the GPT4 model to create a one-paragraph summary.
If it is the beginning of the translation, it will summarize the entire passage sent (the size depending on --accumulated_num
).
If it has any proceeding passage, it will amend the summary to include details from the most recent passage, creating a running one-paragraph context payload of the important details of the entire translated work, which improves consistency of flow and tone of each translation.
Note 1: Use --openai_key
option to specify OpenAI API key. If you have multiple keys, separate them by commas (xxx, xxx, xxx) to reduce errors caused by API call limits.
Note 2: You can just set the environment variable BBM_OPENAI_API_KEY
instead the openai_key. See Environment setting.
Using Caiyun model to translate. The api currently only support:
The official Caiyun has provided a test token (3975l6lr5pcbvidl6jl2). You can apply your own token by following this [tutorial].(https://bobtranslate.com/service/translate/caiyun.html)
bbook_maker --model caiyun --caiyun_key 3975l6lr5pcbvidl6jl2 --book_name test_books/animal_farm.epub\n
"},{"location":"model_lang/#deepl","title":"DEEPL","text":"There are two models you can choose from.
deepl: DeepL Translator.
Need to pay to get the token. Use --model deepl --deepl_key ${deepl_key}
bbook_maker --book_name test_books/animal_farm.epub --model deepl --deepl_key ${deepl_key}\n
deeplfree: DeepL free model
bbook_maker --book_name test_books/animal_farm.epub --model deeplfree\n
Support Claude model. Use --model claude --claude_key ${claude_key}
.
bbook_maker --book_name test_books/animal_farm.epub --model claude --claude_key ${claude_key}\n
"},{"location":"model_lang/#custom-api","title":"Custom API","text":"Support CustomAPI model. Use --model customapi --custom_api ${custom_api}
.
bbook_maker --book_name test_books/animal_farm.epub --model customapi --custom_api ${custom_api}\n
"},{"location":"model_lang/#google","title":"Google","text":"Support google model. Use --model google
--language <LANGUAGE>
Set target languages. All models except for caiyun
supports lots of languages. You can use bbook_maker --help
to check available languages. Default target language is \"Simplified Chinese\"
.
bbook_maker --book_name test_books/animal_farm.epub --model chatgptapi --openai_key ${openai_key} --language ja\n
bbook_maker --book_name test_books/animal_farm.epub --model chatgptapi --openai_key ${openai_key} --language \"Simplified Chinese\"\n
"},{"location":"prompt/","title":"Tweak the prompt","text":"To tweak the prompt, use the --prompt
parameter. Valid placeholders for the user
role template include {text}
and {language}
. It supports a few ways to configure the prompt:
If you don't need to set the system
role content, you can simply set it up like this: --prompt \"Translate {text} to {language}.\"
or --prompt prompt_template_sample.txt
# prompt_template_sample.txt\nTranslate the given text to {language}. Be faithful or accurate in translation. Make the translation readable or intelligible. Be elegant or natural in translation. If the text cannot be translated, return the original text as is. Do not translate person's name. Do not add any additional text in the translation. The text to be translated is: \n{text}\n
If you need to set the system
role content, you can use the following format: --prompt '{\"user\":\"Translate {text} to {language}\", \"system\": \"You are a professional translator.\"}'
or --prompt prompt_template_sample.json
# prompt_template_sample.json\n{\n \"system\": \"You are a professional translator.\", \n \"user\": \"Translate the given text to {language}. Be faithful or accurate in translation. Make the translation readable or intelligible. Be elegant or natural in translation. If the text cannot be translated, return the original text as is. Do not translate person's name. Do not add any additional text in the translation. The text to be translated is:\\n{text}\"\n}\n
You can also set the user
and system
role prompt by setting environment variables: BBM_CHATGPTAPI_USER_MSG_TEMPLATE
and BBM_CHATGPTAPI_SYS_MSG
.
.md
files) for more structured prompts: --prompt prompt_md.prompt.md
# Translation Prompt\n\n## System Message\nYou are a professional translator who specializes in accurate translations.\n\n## Conversation\n\n| Role | Content |\n|-------|------------------------------------------|\n| User | Please translate the following text into {language}:\\n\\n{text} |\n\n# OR using Developer Message (for newer AI models)\n\n# Translation Prompt\n\n## Developer Message\nYou are a professional translator who specializes in accurate translations.\n\n## Conversation\n\n| Role | Content |\n|-------|------------------------------------------|\n| User | Please translate the following text into {language}:\\n\\n{text} |\n
python3 make_book.py --book_name test_books/animal_farm.epub --prompt prompt_template_sample.txt\n# or\npython3 make_book.py --book_name test_books/animal_farm.epub --prompt prompt_template_sample.json\n# or\npython3 make_book.py --book_name test_books/animal_farm.epub --prompt \"Please translate \\`{text}\\` to {language}\"\n
"},{"location":"quickstart/","title":"QuickStart","text":"After successfully install the package, you can see bbook-maker
is in the output of pip list
.
You can use by command bbook_maker
. A sample book, test_books/animal_farm.epub
, is provided for testing purposes.
bbook_maker --book_name ${path of a book} --openai_key ${openai_key}\n\n# Example\nbbook_maker --book_name test_books/animal_farm.epub --openai_key ${openai_key}\n
Or, you can use the script provided by repository.
python3 make_book.py --book_name ${path of a book} --openai_key ${openai_key}\n\n# Example\npython3 make_book.py --book_name test_books/animal_farm.epub --openai_key ${openai_key}\n
Once the translation is complete, a bilingual book named ${book_name}_bilingual.epub
would be generated.
Note: If there are any errors or you wish to interrupt the translation by pressing CTRL+C
. A book named ${book_name}_bilingual_temp.epub
would be generated. You can simply rename it to any desired name.