Argos Translate Documentation

Open-source offline translation library written in Python

Argos Translate uses OpenNMT for translations, SentencePiece for tokenization, Stanza for sentence boundary detection, and PyQt for GUI. Argos Translate can be used as either a Python library, command-line, or GUI application. LibreTranslate is an API and web-app built on top of Argos Translate.

Argos Translate supports installing language model packages which are zip archives with a “.argosmodel” extension with the data needed for translation.

Argos Translate also manages automatically pivoting through intermediate languages to translate between languages that don’t have a direct translation between them installed. For example, if you have a es ➔ en and en ➔ fr translation installed you are able to translate from es ➔ fr as if you had that translation installed. This allows for translating between a wide variety of languages at the cost of some loss of translation quality.

Python Example

import argostranslate.package
import argostranslate.translate

from_code = "en"
to_code = "es"

# Download and install Argos Translate package
argostranslate.package.update_package_index()
available_packages = argostranslate.package.get_available_packages()
available_package = list(
    filter(
        lambda x: x.from_code == from_code and x.to_code == to_code, available_packages
    )
)[0]
download_path = available_package.download()
argostranslate.package.install_from_path(download_path)

# Translate
installed_languages = argostranslate.translate.get_installed_languages()
from_lang = list(filter(
        lambda x: x.code == from_code,
        installed_languages))[0]
to_lang = list(filter(
        lambda x: x.code == to_code,
        installed_languages))[0]
translation = from_lang.get_translation(to_lang)
translatedText = translation.translate("Hello World!")
print(translatedText)
# '¡Hola Mundo!'

Command Line Interface Example

Settings

Set package index

Reads package index at https://raw.githubusercontent.com/argosopentech/argospm-index/main/index.json

export ARGOS_PACKAGE_INDEX="https://raw.githubusercontent.com/argosopentech/argospm-index/main"

View debugging information

Argos Translate prints more verbose logging

export ARGOS_DEBUG=1

Set packages dir

export ARGOS_PACKAGES_DIR="/home/user/.local/share/argos-translate/packages/"

Set device

export ARGOS_DEVICE_TYPE="cpu"
export ARGOS_DEVICE_TYPE="cuda"

Command Line Interface

argos-translate --from-lang en --to-lang es "Hello World"
Hola Mundo

echo "Text to translate" | argos-translate --from-lang en --to-lang es
Texto para traducir

argospm --help
usage: argospm [-h] {update,search,install,list,remove} ...

positional arguments:
  {update,search,install,list,remove}
                        Available commands.
    update              Downloads remote package index.
    search              Search package from remote index.
    install             Install package.
    list                List installed packages.
    remove              Remove installed package.

optional arguments:
  -h, --help            show this help message and exit

Translate a string from English to Spanish.

Note: If you do not have the language pair that you are calling installed, you will get a Traceback error.:

argos-translate --from-lang en --to-lang es "Hello World."
Hola Mundo

Translate longer text piped into argos-translate.:

echo "Text to translate" | argos-translate --from-lang en --to-lang es
Texto para traducir

Update

Downloads remote package index.

argospm update

Install

Install package.

argospm install translate-en_es

List

List installed packages.

argospm list

Remove

Remove installed package.

argospm remove translate-en_es

Enable tab completion for Bash

curl -sSL https://raw.githubusercontent.com/argosopentech/argos-translate/master/scripts/completion.bash > /etc/bash_completion.d/argospm.bash

Importing new pairs through the CLI

  • Update list of available language pairs: argospm update

  • List all available language pairs: argospm search

  • Install new pair syntax: argospm install *lang_pair_name*

For example, install Turkish to English pair: argospm install translate-tr_en

Optionally, you could install all language pairs using BASH.:

for i in $(argospm search | sed 's/:.*$//g'); do argospm install $i ; done

Removing a pair through the CLI

  1. Remove the Turkish to English pair: argospm remove translate-tr_en

Optionally, you could remove all language pairs using BASH if you need to free space fast.

for i in $(argospm list); do argospm remove $i ; done

Graphical User Interface

Run the GUI version of Argos Translate.

argos-translate-gui

Installing a language

When installing with snap a .desktop file should also be installed which will make Argos Translate available from the desktop menu.

Languages are chosen as drop down choices. More languages pairs can be installed.

The left text box translates into the right box.

Example workflow translating from Vietnamese into English:

  • Set the left drop down to Vietnamese and the right drop down to English.

  • Replace the default text Text to translate from in the left text box with some text in Vietnamese. A quick way to do this is to click in the left text box and press the keyboard shortcut CTRL+a to select all and then CTRL+v to paste.

  • Wait patiently.

  • When text appears in the right text box, read the translation!

If the output looks similar to the input, try changing the origin language as some languages appear similar if you are unfamiliar with them.

Adding language pair models from the graphical interface

Language pairs are on average 100MB each.

Installing new pairs through the GUI

  • Open Argos Translate: argos-translate-gui

  • Click on the Manage Packages menu item.

  • Click on the Download packages button.

  • Click on the down arrow beside a language pair that you want to add.

  • Wait for the hourglass icon to change into a check mark icon.

  • Repeat the last two steps until you have all of the language pairs that you want.

  • Click on the X in the top right to close the Download packages window.

  • Click on the X in the top right to close the Manage Packages window.

Note: The Download packages screen does not seem to have a scroll bar so you will probably need to follow the next set of instructions to import new pairs through the GUI.

Importing new pairs through the GUI

Removing a pair through the GUI

  • Open Argos Translate: argos-translate-gui

  • Click on the Manage Packages menu item.

  • Click on the trash can icon besides the pair you want to remove.

  • Click on the X in the top right to close the Manage Packages window.

Examples

Install package from file path

import pathlib

import argostranslate.package

package_path = pathlib.Path("/root/translate-en_it-2_0.argosmodel")

argostranslate.package.install_from_path(package_path)