This is a command-line Java application for translating documents using the DeepL API. It leverages the official DeepL Java SDK (deepl-java) for its core translation functionalities. The application supports a variety of file types and allows users to specify an input file and a target language, automatically generating an output file with the translation.
- Translate documents to various languages supported by DeepL.
- Auto-generates output filename (e.g.,
input.txttranslated to German (DE) becomesinput.txt_DE). - Checks for a predefined list of supported input file extensions before attempting translation.
- Requires DeepL API authentication key to be set as an environment variable (
DEEPL_AUTH_KEY).
- Java Development Kit (JDK) 8 or higher.
- Apache Maven (for building and managing dependencies).
- A DeepL API Pro account (or a Free account with API access) and an authentication key.
-
Clone the repository (or set up the project manually):
git clone https://github.com/DeepLcom/java-document-translator.git cd java-document-translator -
Set your DeepL Authentication Key: Set the
DEEPL_AUTH_KEYenvironment variable to your DeepL API key.export DEEPL_AUTH_KEY="your_deepl_api_key_here"
For persistent storage, add this line to your shell's configuration file (e.g.,
~/.zshrc,~/.bash_profile). -
Build the project using Maven: This will compile the source code and download the necessary dependencies (including the
deepl-javalibrary).mvn compile
Run the application from the project's root directory using Maven:
mvn exec:java -Dexec.args="<inputFile> <targetLang>"Arguments:
<inputFile>: Path to the document you want to translate (e.g.,./report.docxordata/my_text.txt).<targetLang>: The target language code (e.g.,DEfor German,FRfor French,EN-USfor English (US),ESfor Spanish). Refer to the DeepL API documentation for a full list of supported target language codes.
Example:
To translate a file named mydocument.pdf located in your Downloads folder to German:
mvn exec:java -Dexec.args="./mydocument.pdf DE"The translated file will be saved in the same directory as the input file, with _DE appended to its name (e.g., ./mydocument.pdf_DE).
The application performs a preliminary check based on the input file's extension. The following extensions and their descriptions are currently recognized by this custom check:
docx: Microsoft Word Documentdoc: Microsoft Word Documentpptx: Microsoft PowerPoint Documentxlsx: Microsoft Excel Documentpdf: Portable Document Formathtm: HTML Documenthtml: HTML Documenttxt: Plain Text Documentxlf: XLIFF Document, version 2.1xliff: XLIFF Document, version 2.1srt: SubRip Subtitle file
Note: While this application performs a preliminary extension check, the actual document translation capability and supported formats are determined by the DeepL API. Refer to the official DeepL documentation for document translation for the most up-to-date list of supported file types by the API itself.
pom.xml: Maven project configuration, including dependencies likedeepl-java.src/main/java/App.java: Main application class containing the translation logic.src/main/java/HelloWorld.java: A simple Hello World program.src/main/java/Args.java: An older version of the argument parsing logic.
MIT