Open Source Language translate by using libretranslate

Tushar Tiwari
Geek Culture
Published in
2 min readAug 31, 2022

--

What is LibreTranslate?

Simply put, It’s an Open Source Machine Translation API, entirely self-hosted.
Yes, that means you could run it at your premises without being connected to the Internet.
Is this even possible?
Yes, all thanks to Argos Translate which runs its translation engine.

Wanted to give it a try ? Try it online!

Note: This guide is written on Ubuntu.

Installation

Python (3.8 or higher is recommended) by official LibreTranslate.

  1. create a conda environment named py38
  2. Activate py38 environment
  3. Install libretranslate ….⏳
conda create — name py38 python=3.8
conda activate py38
pip install libretranslate

If any faced issue while installing libretranslate and failing atpyicu, then refer.

Alternative way

Directly build form git. I prefer this method

git clone https://github.com/LibreTranslate/LibreTranslate
cd LibreTranslate
pip install -e .

Let’s start the libretranslate Server.

To find out the Language code reference

python main.py --load-only en,hi
# en,hi change these language code according to your need.
  • en : English
  • hi: Hindi

You can see it running at http://127.0.0.1:5000.
If you don’t believe me, turn off your Internet connection and see for yourself.

Demo using API programmatically in Python

  1. Created a text file with few news headlines names `sentence.txt`

2. Run the script shown below.

python english_hindi_API.py 

Gist Link , Sentence.txt

3. Results into a hindi_translation.txt file.

These results are quite good. As the Machine Translation space is improving with time we may get some great results going ahead.

Thanks to LibreTranslate and Argos Translate.

Reference:

  1. https://github.com/LibreTranslate/LibreTranslate
  2. https://github.com/argosopentech/argos-translate

--

--

Tushar Tiwari
Geek Culture

Finding insights from data | Fascinated by how Markets works.