← Journal
Translate Without Calling a Translation API: Running Argos Translate Offline

Translate Without Calling a Translation API: Running Argos Translate Offline

I ran Argos Translate with a local machine-translation model, without a cloud translation API and with network access disabled. An internal dependency attempted a network request, so I traced the cause and fixed it.

Repository covered in this article

argosopentech/argos-translate

Open-source offline translation library written in Python

6.3k Python MIT License

Many applications call an external translation API. For each item, you make a network request and manage an API key, and you send the text you process through a server outside your company. Argos Translate lets you keep the model on the local machine and run the process without network access. I installed the library and verified translation with no network access.

Argos Translate is an offline, neural-network-based machine-translation library. It distributes translation models as packages for each language pair. The source code is available under the MIT License (*1).

1. Install Argos Translate and fetch a language model

I fetched the English-to-Japanese model package at build time, while network access was available, and included it in the image.

FROM docker.io/library/python:3.12.13-slim
RUN pip install --no-cache-dir --quiet 'argostranslate==1.11.0'
COPY install_model.py /tmp/install_model.py
RUN python /tmp/install_model.py
WORKDIR /work
# install_model.py
import argostranslate.package
import argostranslate.translate

argostranslate.package.update_package_index()
available = argostranslate.package.get_available_packages()
pkg = next(p for p in available if p.from_code == "en" and p.to_code == "ja")
path = pkg.download()
argostranslate.package.install_from_path(path)
print("installed:", pkg)

# also triggers the first download of the sentence-splitting model (more on this below)
warmup = argostranslate.translate.translate("Warm up the pipeline.", "en", "ja")
print("warmup translation:", warmup)
podman build -t argos-translate-sandbox .

2. The snag: the offline run fails

I ran a translation with network access disabled in the image I had built.

podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 \
  -v "$(pwd)":/work -w /work argos-translate-sandbox \
  python translate_demo.py

The -v option makes the specified directory readable and writable from the container. Run this command in a dedicated empty directory for the experiment. Do not place secret keys or credentials there.

The command failed with an error.

urllib3.exceptions.NameResolutionError: HTTPSConnection(host='raw.githubusercontent.com', ...):
Failed to resolve 'raw.githubusercontent.com' ...
File ".../argostranslate/sbd.py", line 149, in lazy_pipeline
    self.stanza_pipeline = stanza.Pipeline(...)

The translation model was local. Stanza, the internal dependency responsible for sentence segmentation (deciding where to split sentences), tried to fetch a configuration file from GitHub and failed. Stanza's Pipeline() uses DOWNLOAD_RESOURCES as the default download_method. With a local model, Stanza fetches the latest configuration file over the network before it can use the local resources. Argos Translate includes a local configuration file (resources.json). Its filename does not match the file Stanza searches for. Stanza could not find the local file and attempted a network request.

3. Fix: reuse the local resources

Stanza provides a REUSE_RESOURCES setting that tells it to use local resources without checking the network. Argos Translate does not pass this value, so I wrapped Stanza's Pipeline in my own script and overrode the default.

import functools
import stanza
from stanza.pipeline.core import DownloadMethod

stanza.Pipeline = functools.partial(
    stanza.Pipeline, download_method=DownloadMethod.REUSE_RESOURCES
)

import argostranslate.translate

text = "Open source software lets anyone read, modify, and redistribute the code. This freedom is why so many developers trust it for critical infrastructure."
translated = argostranslate.translate.translate(text, "en", "ja")
print("INPUT: ", text)
print("OUTPUT:", translated)

I reran the command with the same --network none setting.

INPUT:  Open source software lets anyone read, modify, and redistribute the code. This freedom is why so many developers trust it for critical infrastructure.
OUTPUT: オープンソースソフトウェアは、コードを読み、変更、再配布することができます。 この自由は、多くの開発者が重要なインフラを信頼する理由です。

The translation completed with zero network traffic. The sentence boundaries were natural, and the meaning remained intact.

A local model does not guarantee offline execution. A library can include a dependency that issues its own network request. Use --network none and inspect the dependency below the translation model when the run raises an error.

Translation without a cloud service

You can run some translation tasks without an external API. Keep the model on the local machine and verify offline execution. That setup lets you translate text that must stay within the company without giving up the translation feature. Adding one option gives you more design flexibility.

Sources

*1 Argos Translate (GitHub), https://github.com/argosopentech/argos-translate, MIT License