How Firefox Translations Works Locally Without the Cloud
Firefox Translations provides completely private web page translation by running advanced machine learning models directly on a user's device rather than relying on third-party cloud servers. This article explains the specific technologies behind this feature, detailing how Firefox downloads compact language models on demand, utilizes WebAssembly and CPU optimizations to process neural networks locally, and seamlessly replaces web page text while keeping your browsing data completely offline.
The Bergamot Project Engine
At the core of Firefox Translations is an open-source engine developed by the Bergamot Project, a consortium led by Mozilla and researchers from the University of Edinburgh, Charles University, the University of Sheffield, and the University of Tartu.
This engine is built on Marian NMT, a highly efficient Neural Machine Translation framework written in C++. While traditional neural translation tools require massive cloud server farms to process text, the Bergamot engine is specifically engineered to execute complex neural network calculations using the limited memory and processing power of standard consumer computers and mobile devices.
Execution via WebAssembly and SIMD
To run a C++ translation engine securely inside a web browser, Mozilla compiles the Bergamot code into WebAssembly (Wasm). WebAssembly is a binary instruction format that allows complex code to run inside the browser's sandbox environment at near-native speeds.
Because most consumer devices do not have dedicated, high-end graphics cards (GPUs) to accelerate machine learning tasks, Firefox relies entirely on the device's central processor (CPU). To make CPU-based translation fast enough for real-time web browsing, Firefox utilizes WebAssembly SIMD (Single Instruction, Multiple Data). SIMD allows the CPU to perform the same mathematical operation on multiple pieces of data simultaneously. This parallel processing drastically speeds up the matrix multiplications required by the translation neural network.
Compact, On-Demand Language Models
Standard machine learning models for language translation often take up gigabytes of storage space, making it impossible to bundle them directly into the Firefox installer. Mozilla solves this through two techniques:
- Model Compression and Quantization: Mozilla shrinks the neural networks by reducing the numerical precision of the model's parameters (quantization) from 32-bit floating-point numbers down to 8-bit integers. By combining this with teacher-student model training—where a massive, accurate model trains a much smaller model—the file size is reduced to roughly 15 to 20 megabytes per language pair without a noticeable drop in translation quality.
- On-Demand Caching: Firefox does not come pre-installed with these models. When you visit a foreign-language website and request a translation for the first time, Firefox automatically downloads the specific language model required. The model is saved locally in your browser's storage cache. From that point forward, translations for that language happen entirely offline.
Translating the Document Object Model (DOM)
Translating a live web page requires more than just converting raw text; the browser must maintain the website's layout, interactive elements, and styling.
When a translation is triggered, Firefox scans the web page's Document Object Model (DOM) to extract visible text nodes while ignoring underlying code and scripts. To make the translation feel instantaneous, the browser prioritizes the text currently visible on your screen (the viewport) before translating the rest of the page in the background as you scroll.
As the extracted text is fed into the local Bergamot engine, the system tracks the placement of inline HTML tags, such as bold text, italics, and hyperlinks. Once the neural network generates the translated sentences, the engine automatically maps the HTML formatting onto the new words and injects the translated text back into the DOM, delivering a fully formatted, translated web page without a single word ever leaving your device.