tgbatch is a robust Java-based Command Line Interface (CLI) application built to automate the translation of ebooks using Google Cloud's Gemini AI models. It processes ebooks in batches, respects API rate limits, embeds custom prefaces (such as copyrights or generation disclaimers), and compiles the translated text directly back into a structured ebook format.
Currently, the application natively supports EPUB files and is architected to scale into multi-format conversions in the future.
-
Java Runtime: Java 21 or higher.
-
Google Cloud Credentials: A valid Google Cloud Project ID and a Gemini API Key.
-
Internet Access: To securely dispatch requests to Google Vertex AI API endpoints (
us-central1).
To output standard usage syntax and verify the application context layout:
Bash
$ java -jar tgbatch.jar -help
Usage: tgbatch [-hV] [-b=<count>] [--backoff-initial-ms=<ms>]
[--backoff-max-ms=<ms>] [--backoff-max-total-ms=<ms>]
[--backoff-multiplier=<factor>] [-d=<ms>] -i=<path> -k=<key>
-l=<path> [-m=<name>] -o=<path> [--preface=<text>] [-s=<lang>]
-t=<lang>
Translates Ebooks using Gemini API with native logging and exponential backoff
configuration.
-b, --batch-size=<count> Number of sentences per request.
--backoff-initial-ms=<ms>
Initial backoff delay in milliseconds for 503/429
errors.
--backoff-max-ms=<ms> Maximum capping backoff interval limit in
milliseconds.
--backoff-max-total-ms=<ms>
Maximum elapsed cumulative backup limit timeline
in milliseconds.
--backoff-multiplier=<factor>
Multiplicative factor to increase backoff delay on
failures.
-d, --sleep=<ms> Standard base sleep time in millis between
successful batches.
-h, --help Show this help message and exit.
-i, --input=<path> Path to the source ebook file.
-k, --api-key=<key> Google AI Studio Gemini API Key.
-l, --log-file=<path> Path to the output application log file.
-m, --model=<name> Gemini model name.
-o, --output=<path> Path to the destination translated ebook file.
--preface=<text> Custom preface text.
-s, --source-lang=<lang> Source language.
-t, --target-lang=<lang> Target language.
-V, --version Print version information and exit.
In this example, we translate a book from English to Italian using the latest flash model gemini-flash-latest. We set an API request grouping of 30 sentences, integrate a 30 seconds safety delay to safely circumvent tier quotas, and inject a corporate copyright disclaimer page as the front chapter:
Bash
nohup java -jar target/tgbatch.jar \
-i "source_books/the_great_gatsby.epub" \
-o "output_books/il_grande_gatsby_IT.epub" \
-k "AIzaSyD_ExampleGeminiKeyValueHere_9x8w" \
-l "logs/gatsby_translation.log" \
-s "English" \
-t "Italian" \
-m "gemini-flash-latest" \
-b 30 \
-d 30000 \
--preface "© 2026 SemanticArtworks Ebooks Lab. This volume was automatically compiled and translated from its original English edition using Google Gemini 1.5 AI systems. All intellectual property rights are reserved to the original copyright owners." \
--backoff-initial-ms 2000 \
--backoff-multiplier 2.0 \
--backoff-max-ms 60000 \
--backoff-max-total-ms 300000 > /dev/null 2>&1 & echo $! > translation.pid
Kill the process by:
kill $(cat translation.pid)
java -jar tgbatch.jar -k "your api key" -l "logs/discovery.log" --list-models
When triggered, the command line interface outputs live contextual execution progress checkpoints:
Plaintext
=== Starting Ebook Translation Process ===
Connecting to Google AI services using model: gemini-1.5-pro
Reading source file...
Found 4210 text sentences to process.
Adding preface...
Translating block (25/4210 sentences)...
Translating block (50/4210 sentences)...
...
Compiling and saving the translated ebook...
=== Translation completed successfully! ===
Output saved to: /absolute/path/output_books/il_grande_gatsby_IT.epub