Skip to content

DeepLcom/java-document-translator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Document Translator

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.

Features

  • Translate documents to various languages supported by DeepL.
  • Auto-generates output filename (e.g., input.txt translated to German (DE) becomes input.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).

Prerequisites

  • 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.

Setup

  1. Clone the repository (or set up the project manually):

    git clone https://github.com/DeepLcom/java-document-translator.git
    cd java-document-translator
  2. Set your DeepL Authentication Key: Set the DEEPL_AUTH_KEY environment 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).

  3. Build the project using Maven: This will compile the source code and download the necessary dependencies (including the deepl-java library).

    mvn compile

Usage

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.docx or data/my_text.txt).
  • <targetLang>: The target language code (e.g., DE for German, FR for French, EN-US for English (US), ES for 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).

Supported File Types (Custom Check)

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 Document
  • doc: Microsoft Word Document
  • pptx: Microsoft PowerPoint Document
  • xlsx: Microsoft Excel Document
  • pdf: Portable Document Format
  • htm: HTML Document
  • html: HTML Document
  • txt: Plain Text Document
  • xlf: XLIFF Document, version 2.1
  • xliff: XLIFF Document, version 2.1
  • srt: 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.

Project Structure

  • pom.xml: Maven project configuration, including dependencies like deepl-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.

License

MIT

Links

About

This is a command-line Java application for translating documents using the DeepL API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages