How Safari's On-Device Webpage Translation Works

This article explains the mechanics behind the Safari web browser's built-in translation feature. It covers how Safari detects foreign languages on a webpage, seamlessly replaces the text while preserving the site's layout, and utilizes downloadable language models alongside the Apple Neural Engine to offer a completely private, on-device translation option.

Language Detection

Before any translation happens, Safari must determine the language of the webpage you are visiting. This initial step always happens locally on your device. Safari inspects the webpage’s HTML code—specifically looking at the language attributes—and analyzes a sample of the visible text on the screen.

It then compares the detected language against the "Preferred Languages" list in your device's system settings. If the webpage's language is not on your preferred list, and it is a language Apple supports, the translation icon automatically appears in the Safari address bar.

Text Extraction and Layout Preservation

When you tap the translate button, Safari does not translate the entire webpage all at once. Instead, it interacts with the webpage's Document Object Model (DOM), which is the structural map of the site.

Safari isolates the visible text nodes while ignoring the underlying HTML tags and CSS styling. This ensures the website's design, buttons, and layout remain intact. To save bandwidth and processing power, Safari only processes the text currently visible on your screen. As you scroll down the page, Safari dynamically extracts new paragraphs, translates them, and injects the translated text back into the exact spots where the original text lived.

Standard Cloud-Based Translation

By default, Safari uses a cloud-based method to translate webpages. Once Safari extracts the text from the webpage, it sends those text snippets over an encrypted connection to Apple’s servers.

Apple’s servers run large, complex neural machine translation models that analyze the context of the sentences rather than just translating word-for-word. The servers return the translated text to Safari, which immediately displays it on your screen. While this data is sent to the cloud, Apple randomizes the identifiers so the requests are never linked to your Apple ID, and the webpage contents are not stored.

How the On-Device Translation Option Works

For users who want maximum privacy or need to translate content without an internet connection, Apple offers an on-device translation option. This feature shifts the heavy lifting from Apple’s cloud servers directly to your iPhone, iPad, or Mac.

To make this possible, Safari relies on two core components:

1. Downloadable Language Models

Cloud servers have massive storage capacity for language databases, which your device lacks by default. To bypass the cloud, you must manually download specific language packs in your device's Settings app. These packs contain compressed, highly optimized machine learning models for the languages you choose.

2. The Apple Neural Engine

Running neural machine translation requires significant computing power. When you trigger a translation in Safari with on-device mode enabled, the browser routes the extracted webpage text directly to the downloaded language packs stored on your device's internal flash storage.

Your device then uses the Apple Neural Engine—a specialized processor built into Apple Silicon chips designed specifically for machine learning tasks. The Neural Engine processes the natural language algorithms locally at high speeds, translating the text and feeding it back to the Safari DOM in real time.

Differences Between Cloud and On-Device Modes

When using the on-device option, not a single byte of the webpage's text leaves your browser to go to Apple. The entire process of detection, extraction, translation, and text replacement happens inside your device's memory.

While the cloud-based method may occasionally offer slightly more nuanced translations due to the massive size of server-side models, the on-device models are engineered to be nearly identical in accuracy for everyday reading, all while functioning completely offline and keeping your browsing history strictly private.