Skip to content

Program to translate .txt and .md files in multiple languages with the help of LLM

License

Notifications You must be signed in to change notification settings

Asi0Flammeus/LLM-Translator

Repository files navigation

LLM-Translator

LLM-Translator is a simple CLI tool to translate any .txt and .md files of any length in the supported languages by leveraging ChatGPT's API.

Supported Languages

Texts and documents are translated into the Modern Standard version of the following languages:

Language Code Speculative Translation Accuracy
English en 1.00
German de 0.90 - 0.95
Spanish es 0.90 - 0.95
Italian it 0.85 - 0.90
Portuguese pt 0.85 - 0.90
French fr 0.90 - 0.95
Swedish sv 0.80 - 0.85
Arabic ar 0.70 - 0.80
Japanese ja 0.70 - 0.80
Swahili sw 0.75 - 0.80
Afrikaans af 0.75 - 0.80
Danish da 0.80 - 0.85
Greek el 0.75 - 0.80
Georgian ka 0.65 - 0.75
Thai th 0.65 - 0.75
Turkish tr 0.70 - 0.80

You can manually add new languages by modifying language_info in languages.py. You can also change the prompt template by modifying supported_languages/prompt_template.txt. Once modified, the program will automatically update the prompt of every supported languages. Or you can modify the prompt to a specific language by edditing the associated .json file of the language in the /supported_languages folder.

Installation and Setup

Prerequisites

Before utilizing this tool, ensure that you have an OpenAI account and an OpenAI API key and to follow the installation procedure.

Installation for Linux Users

LLM-Translator has been successfully tested on Ubuntu 20.04.

  1. Open a Terminal

  2. Check that Python 3 and git are installed

    • python3 --version
    • most of the time they are installed by default, if not install them with:
    • sudo apt install python3 python3-pip python3-env git
  3. Clone the Repository

    • git clone https://github.com/Asi0Flammeus/LLM-Translator.git
  4. Navigate to the Project Directory:

    • cd LLM-Translator/
  5. Set Up OpenAI API Key:

    • Create a .env file.
    • nano .env
    • press Ctrl+X and then y and Enter to quit nano and save file.
    • Add the following line, replacing "YOUR_API_KEY" with your actual OpenAI API key (go here for futher details).
    • OPENAI_API_KEY="YOUR_API_KEY"
  6. Create a Python Virtual Environment:

    • python3 -m venv env
  7. Activate the Virtual Environment:

    • source env/bin/activate
  8. Install Required Libraries:

    • pip3 install -r requirements.txt

Installation for Windows Users

LLM-Translator has been successfully tested on Windows 11.

By default, Python 3 and git are not already installed on Windows so I will also explain how to install them. If you already have those installed you can directly jump to step 4.

  1. Download Python on official website
  • Execute the installer wizard, python-3.11.5-amd64.exe for example.
    • ⚠️ Beware to tick the Add python.exe to PATH option on the first installation page before cliking the Install Now button.
    • Follow the installation procedure and choose default settings.
  1. Download GitBash on official website
  • Execute the wizard installer, git-2.42.0.2-64-bit.exe for example.
  • Follow the installation procedure and choose default settings.
  1. Open Git Bash

  2. Clone the Repository

    • git clone https://github.com/Asi0Flammeus/LLM-Translator.git
  3. Navigate to the Project Directory:

    • cd LLM-Translator/
  4. Set Up OpenAI API Key:

    • Create a .env file.
    • nano .env
    • Add the following line, replacing "YOUR_API_KEY" with your actual OpenAI API key (go here for futher details).
    • OPENAI_API_KEY="YOUR_API_KEY"
    • Press Ctrl+X and then y and Enter to quit nano and save file.
  5. Create a Python Virtual Environment:

    • python -m venv env
  6. Activate the Virtual Environment:

    • source env/Scripts/activate
  7. Install Required Libraries:

    • pip install -r requirements.txt
  8. Make Script Executable:

    • chmod +x ./run-LLM-Translator.sh for Linux user
    • chmod +x ./run-LLM-Translator-on-windows.sh for Windows user

LLM-Translator Usage

Please follow these steps each time you want to run LLM-Translator:

  1. Open a terminal (or Gitbash for windows users)
  • Go to LLM-Translator directory
  • cd LLM-Translator
  1. activate the Python Environment

    • source env/bin/activate
    • or source env/Scripts/activate for windows users
  2. Prepare Input Files:

    • Before running the program, you have to create subfolders inside the /inputs/ directory and populate them with .txt and .md files that you wish to translate.
    • All the files in a subfolder should be written in the same language.
  3. Execute the Program:

    • .run-LLM-Translator.sh for linux users
    • run-LLM-Translator-on-windows.sh for windows users
  4. Follow the On-screen Instructions

Note: Translations will be automatically stored in an associated subfolder into the /outputs/ folder. Note 2: A better installation process will be done soon™ with executable files for windows and linux.

Roadmap

  • Language Selection
  • Improved Output Organization
  • Comprehensive Testing and Continuous Integration
  • Integration with ChatGPT-4 Model
  • Development of a User-Friendly GUI
  • Integration with Additional LLM Models

Contributing

Contributions are welcome. To contribute, please fork the repository and create a pull request with your changes. Ensure that changes are tested and existing functionality is maintained.

Here we promote Value for Value model so if you find value in this humble script tips are welcomed via LN or by scanning directly this QR code with a Lightning wallet 👇.

License

This project is governed by the MIT License. For more information, refer to the LICENSE file.

About

Program to translate .txt and .md files in multiple languages with the help of LLM

Resources

License

Stars

Watchers

Forks

Packages

No packages published