Repository navigation
Translation
English · Italiano
Pocket Travel translates in two separate places, with different engines. On the device, an offline translator translates between Italian and English. In the data pipeline, a model on the PC translates parts of the English guides into Italian before publication. The commands are in the developer guide docs/GUIDA.md (Italian) and in the pipeline README (Italian).
The core:translate module uses bergamot-translator, the engine of Mozilla's Firefox Translations. bergamot-translator is a C++ library built on Marian, a C++ framework for neural machine translation (the source is marian-dev). It translates on the device, offline.
The project does not use Google Play Services. CI checks that the APKs contain no classes from Google Play Services, Firebase, Play libraries or ML Kit (see Publishing). For this reason the ML Kit translator is not an option.
bergamot-translator and the Firefox Translations models have the MPL-2.0 license. The Licenses screen shows it for both, with the link to the source and the notices of the libraries compiled into the app (Marian, SentencePiece, ruy, PCRE2, zlib, Zstandard and others). bergamot-translator has no official AAR: it is built from source with the NDK and CMake.
BergamotTranslator loads one model for one translation direction, for example from Italian to English. The two directions are two separate models. Each model has three files: the quantized model (.bin), the vocabulary (.spm) and the word list for translation (lex…bin). The vocabulary is the same in both directions: Firefox publishes two identical files, and the app keeps one.
Marian chooses the format from the file suffix and stops with a different suffix: BergamotTranslator checks the suffixes before loading. Loading immediately runs a test translation. This way a broken file fails at load time and not at the first translation, and the memory measured after loading is the real one.
Translations run one at a time, off the calling thread. The JNI bridge makes Marian throw an exception instead of calling std::abort(), and no C++ exception crosses the JNI boundary: an error returns to Kotlin as a failure, with the reason in the log. Texts and paths pass as UTF-8 bytes, because the UTF functions of JNI break emoji. Model loads and releases run one at a time, because they touch registries shared by the whole process.
The models are the Italian ↔ English pair of Firefox Translations, version 3.0, base-memory variant. They come from the Firefox CDN and are described in the Remote Settings collection translations-models-v2. The version is pinned in BergamotModels and is not read from the registry at startup. A new model arrives with an app release, after testing on the phone.
In Settings, under the assistant's models, "Download translation" downloads the six files of the pair: 50 MB compressed, 73 MB on the device. The download is a WorkManager job (BergamotModelDownloadWorker). The files go in translate/, inside the folder of the AI models.
Each file is checked with two sha256 hashes published by Firefox: one of the compressed file and one of the decompressed file. In Storage, the "Offline translation" section shows the space used and "Delete". If Android restricts the app's network, the download stops with the same message as the AI models (see Network restricted by Android).
zstd (Zstandard) is a lossless compression format, and Firefox publishes the models as .zst files. The same JNI library as bergamot-translator contains the zstd 1.5.7 decompressor (BSD-3-Clause license, class Zstd). Only the common parts and decompression are compiled, without assembly, threads and legacy formats. The build downloads the source once and checks its sha256.
bergamot-translator is the submodule third-party/bergamot-translator, pinned at commit 9271618 of May 12, 2024. The tag v0.4.5 does not run on ARM, and after that commit the project has no more releases. The inner submodules (marian-dev, ssplit-cpp and the Marian libraries) are fetched only if the build uses them: the others weigh hundreds of MB. The origin of the submodules and of the patches is described in Submodules and patches.
The submodule stays identical to upstream. The CMake of core:translate builds a copy in core/translate/.cache/cxx/bergamot-src, with the project's patches applied in name order. The copy comes from the submodule commits (git archive), not from the checkout files. With core.autocrlf=true the files would have Windows line endings, and the patches would not apply. The copy is rebuilt only when the commits, the patches or the CMake change. A lock prevents the two ABIs from rebuilding it at the same time.
The LGPL (GNU Lesser General Public License) is a copyleft license: whoever distributes an LGPL library compiled into the app must allow it to be replaced. The copy excludes the nonbreaking_prefixes files of ssplit-cpp, which are LGPL-2.1. Without those files the engine writes a warning and works anyway. Eigen is compiled with EIGEN_MPL2_ONLY: none of its LGPL headers enter the build.
ssplit-cpp would download PCRE2 from GitHub during compilation, without a hash check and with the two ABIs in the same folder. The CMake downloads PCRE2 10.39 once instead, with its sha256.
The release builds only arm64-v8a, the debug build also x86_64 for the emulator. On arm64 matrix computation uses ruy, on x86_64 intgemm. On x86_64, USE_WASM_COMPATIBLE_SOURCE is needed, because without it Marian has no floating-point sgemm and stops at run time. Without debug symbols (-g0) the libraries weigh tens of MB less. The symbols of the static libraries stay internal to libbergamot-jni.so.
A patch that does not apply makes the build fail with its name. git apply exits without error even when it skips all files: the CMake checks that git_revision.h exists, a file that only patch 0006 creates. Before the build, CI checks that the patches apply and warns, without failing, when a patch turns out to be already in the submodule.
There are eleven bergamot-translator patches, in third-party/patches/bergamot-translator. Each patch states in its description the upstream PR or issue ("Upstream:") and when it can be removed ("Da togliere quando:"). marian-dev and bergamot-translator have had no commits since May 12, 2024, ssplit-cpp since Aug 7, 2023. Where the table says "none", the GitHub search of Nov 17, 2026 found no PR or issue.
| Patch | What it changes | Upstream | Remove when |
|---|---|---|---|
0001-marian-faiss-pmmintrin |
Adds <pmmintrin.h> in faiss/VectorTransform.cpp, where SSE is present: with the NDK 29 clang on x86_64 it does not compile |
issue 113 of browsermt/marian-dev, open, no fix | marian-dev includes the header, or the build no longer uses faiss |
0002-marian-pathie-api26 |
pathie-cpp uses iconv and glob(), which the NDK has only from API 28; minSdk is 26. Below API 28 the conversion returns the string as is and glob an empty list |
none | minSdk rises to API 28, or pathie-cpp no longer uses iconv and glob()
|
0003-sentencepiece-constexpr |
In trainer_interface.cc a constexpr outside the enum range becomes const: with the NDK 29 clang it does not compile |
none on google/sentencepiece; marian-dev uses an old sentencepiece | marian-dev moves to a sentencepiece that compiles with the NDK in use |
0004-ssplit-pcre2-generatore |
Passes the parent's Ninja generator to the PCRE2 child project: without it, on Windows it picks Visual Studio and the Android build fails | none on browsermt/ssplit-cpp |
FindPCRE2.cmake passes the generator, or the build no longer uses the internal PCRE2 |
0005-marian-senza-git-submodule |
Removes the git submodule update run at every configuration: from the git copy it goes up to the project's repository and, with two ABIs in parallel, fails on the lock |
none | marian-dev no longer updates submodules from CMake, or the build compiles from a copy with .git
|
0006-marian-senza-git-revision |
Replaces the generation of git_revision.h with a fixed value: the copy has no .git. The file is also used to check that the patches are applied |
none | marian-dev does not require .git for the version, or the build compiles from a copy with .git
|
0007-marian-tensor-allocator-grow |
Makes the workspace grow in 1 MB blocks instead of 128 MB, and the memory peak drops. Mozilla does this only for WASM | commit 724fc93 of mozilla/translations (PR 1135), WASM only | marian-dev reduces the block for Android too, or the peak no longer matters |
0008-marian-logger-riusabili |
Reuses the general and valid loggers if they already exist: a second model in the same process stopped the process |
the same change in tetherto/qvac-ext-marian-dev; no PR opened by the project | marian-dev reuses the registered loggers, or the project loads only one model per process |
0009-memoria-al-caricamento |
Frees the model copy after loading. Mozilla measures from 99 MB less with the tiny model to 323 MB less with the base | commit 724fc93 of mozilla/translations (PR 1135) | marian-dev includes the shared bytes and clearItems(), or memory at load time no longer matters |
0010-marian-version-nella-build-dir |
Writes project_version.h in the build folder of each ABI and not in the source copy, which the two ABIs share |
none | marian-dev writes the file in the build folder, or the copy is no longer shared between the ABIs |
0011-marian-niente-gestori-di-errore |
On Android it does not install Marian's SIGSEGV, SIGFPE and set_terminate handlers: a crash of llama.cpp or MapLibre would become a hang or a misleading SIGABRT
|
none | marian-dev does not install the handlers from the library, or Marian no longer runs in the app process |
Patch 0009 has a cost. After the first load, the model copy read from the file is gone, and a second backend of the same model cannot be created. The project uses a single backend per model (BlockingService). Patch 0009 does not carry over the debug logs, MemoryBundle::clear() (it freed the same memory twice) or the WASM build script from Mozilla's commit.
The code on main, not yet in a release, contains the download and deletion of the model pair and the entries of the Licenses screen. No app screen uses BergamotTranslator yet: only the on-device test of core:translate uses it. A translation screen will come in a later version.
"Translate" in the Ask the assistant sheet does not use bergamot-translator. The question goes to the assistant's model (see Ask the assistant from other apps).
- ML Kit: it is a Google library, and CI rejects the APKs with its classes.
- The bergamot-translator tag v0.4.5: it does not run on ARM.
- The model version read from the Firefox registry at startup: an untested new model would reach phones without an app release.
- Changes inside the submodule: with the patches kept separate the build stays reproducible, and an update is a commit change.
- There is no screen for translating yet.
- The languages are only Italian and English.
- The translation is automatic and can contain errors, as the note on the Licenses screen says.
- A model has a single backend, because of patch 0009.
- Without the
nonbreaking_prefixesfiles the engine writes a warning. - The release contains the library only for arm64-v8a.
The English guides contain the Government of Canada's travel advice from travel.gc.ca (see Travel advice in the English guides). translate_guides.py translates into Italian, paragraph by paragraph, the four sections of the English guide that apply to all travelers and that the en pass publishes. They are Safety and security, Laws and culture, Natural disasters and climate, and Health, each with "(Government of Canada)" in the title.
The sections for Canadians only are not translated: entry requirements, addresses and numbers stay in the English guide (see Sections for a single nationality). Wikipedia sections are never translated: they come from the article in the guide's language.
generateGuides adds the translated sections at the end of the Italian guide, after the Wikivoyage sections. The titles are fixed, because the model gets them wrong out of context. The translated sections have translated = 1, a column that old apps ignore. The app copies the column into region.db (schema version 24). In the guide's Sources it writes "machine-translated" next to the site of the page the section comes from. The Licenses screen has a note on the translated sections and names the model.
The model is Index-Translate-9B, with the Apache 2.0 license, in the quantized GGUF format Q4_K_M. GGUF is the format of llama.cpp models. The model runs on llama-server, llama.cpp's HTTP server, on the PC's GPU.
The choice comes from a blind review of Oct 31, 2026, on mixed text from Wikivoyage and the Government of Canada. Index-Translate-9B had 0.3% of sentences with serious defects. The prompt asks for the impersonal register and carries the region and the category. llama-server translates several paragraph blocks together, with a shared KV cache.
Each translated section records in translatedBy the id of the model that translated it. The field says which model wrote a text, as the AI Act requires. The guides are republished even when only the model that translated a section changes.
The generator of the assistant's training dataset accepts only sections translated by a model with a verified license: opus-mt, Gemma 4 and Index-Translate. Gemma 3 and TranslateGemma are left out: under the Gemma Terms of Use (1.1(e)(iii)) a model trained on their texts becomes a derivative. Sections without translatedBy are also left out: they were translated before the field existed, and their model is unknown. The dataset is described in Models and training.
MarianMT is the name of the Helsinki-NLP translation models built with Marian. The pipeline uses opus-mt-tc-big-en-it and opus-mt-tc-big-it-en (CC BY 4.0), run with CTranslate2 in int8 on the CPU. Until Index-Translate, the Canadian advice was translated with MarianMT.
A sample review on Oct 9, 2026 checked 1,786 sentences translated from English one by one, for omissions, additions, numbers and meaning. With MarianMT, 21% of the sentences of the Wikivoyage sections had critical or serious errors, against 5.8% of those of the Government of Canada. The errors come from ambiguous words: "Muggings" became "I muggini", "tip" became "consigliare".
With MarianMT, the comparison with the Wikivoyage sections stays off (WIKIVOYAGE_SECTIONS), in both directions and for cities. The Index-Translate engine translates only guides from English to Italian.
The AI Act is the European regulation on artificial intelligence. Article 50(4) requires that a text on safety, health or laws published by an AI be declared on the content itself, not only in the Sources. The obligation holds until the text has a full human review with editorial responsibility; sample checks are not enough. Each translated section therefore shows "Machine-translated with an AI model, partially reviewed" under its title.
- The register is checked with Morph-it!, a morphological lexicon of Italian. A translation that addresses the reader as "tu" or "voi" goes back to the model for the impersonal form. The rewrite is kept only if it changes little beyond the flagged words.
- On Oct 9, 2026 the 495 most frequent sentences, about half of the text, were reviewed one by one.
translation-corrections.en-it.tsvcontains the 268 that needed correcting. These translations take precedence over the model and do not go through the automatic check. - The automatic check discards sentences with " ⁇ ", the sign of a character the model does not know (Cyrillic, currency symbols, some accented letters). This way those sentences never come out garbled.
- A paragraph with numbers different from the original or with an out-of-range length is not saved. The number check accepts the Italian forms: times ("8 p.m." and "20:00"), "24/7" as "24 ore su 24, 7 giorni su 7", centuries ("19th century" and "XIX secolo" or "Ottocento"), decades ("1990s" and "anni '90"), thousands written another way and numbers up to 12 in words.
- Sentences are not split after abbreviations such as "U.S." and "St.". The rule holds in the translation, in the filter of the English guide's advice and in the translated SFT dataset.
Where the English guide is richer, the English section translated with Index-Translate takes the place of the Italian category. It is richer when the Italian section is absent, under 300 characters or less than half as long. The translated sections use the titles that the Italian guides already have: "Get in" becomes "Come arrivare".
Only the Wikivoyage sections are compared, not Wikipedia or the governments' advice. The English Useful phrases are translated when they are prose about languages and dialects. A list of phrases stays out, because the pronunciation is written for English speakers. The English Quick facts are not translated: the pipeline builds them from the Italian ones. The sections appear when the translations asset contains them.
The English guides have no sections translated from Italian: they come from the English Wikivoyage pages (see Two languages).
Translation runs on the PC, under gpu_lock.py, which allows one GPU job at a time (see One job at a time on the GPU). It does not start if another process, for example the Android emulator, occupies more than 10% of the GPU memory; the --max-vram-held option raises the threshold. The commands are in the README of tools/data-pipeline (Italian), section "Città, guide e dataset di addestramento".
publish-regions runs on GitHub's ubuntu-24.04 runners, which have no GPU. The first pass on the Canadian advice took more than three hours even with the GPU. The workflow therefore does not translate: it reads the translations made on the PC.
Each paragraph goes to disk as soon as it is translated. An interruption does not lose the work done, and the same call resumes from where it stopped. A block that fails does not stop the others. On the PC, translation has no time limit.
- The first pass on the Canadian advice: 18,752 paragraphs in 206.5 minutes on an RX 7700 XT, with Vulkan and one block at a time.
- On 752 test paragraphs, four blocks together take 3.5 minutes instead of 8–9, the same with ROCm and with Vulkan. The translations change little between tests: mostly the order of the sentence or a different impersonal form.
The translations file has one JSON line per paragraph: the key (sha1 of the direction and the English paragraph), the translation, the model and the prompt version. A file contains the translations of a single model. The same file serves as the cache for later passes on the PC.
The file is uploaded by hand, compressed, to the asset guide-translations.en-it.jsonl.xz of the guide-translations release. publish-regions downloads it and applies it to the travel.gc.ca sections that the English pass publishes, therefore after the English guides. The same asset carries the translated Wikivoyage sections. The workflow side is described in Guide translation, in Publishing.
Everything runs with the repository variable TRANSLATE_GUIDES equal to true, currently on. The step is never blocking: without an engine, model or time the guide comes out as is. If the variable is turned off, the translated advice already published stays, without updates.
The paragraphs that the file does not translate yet end up in the job's guide-translations-missing artifact, that is, in a file attached to the run. They are the English paragraphs that are new or changed since the last pass on the PC, and the translations discarded by the number check, which must be reread by hand.
A category with a paragraph without a translation does not use the new translation. For the Canadian advice the already published translation stays; the first time, the category stays out of the Italian guide. For the Wikivoyage sections the Italian section stays. The new translation enters when the paragraph is translated on the PC and the asset is uploaded again.
publish-regions also prepares MarianMT for the city guides (action setup-translation), with a limit of 120 seconds for each cities.db and 40 minutes per shard. With the comparison of the Wikivoyage sections off for MarianMT, cities currently receive no translated sections. A city is matched to the page in the other language through the shared Wikidata item, because the title often changes (Venezia, Venice).
- Translations go only from English to Italian.
- A new or changed paragraph enters the Italian guide only after a pass on the PC and the manual upload of the asset.
- Human review is partial: 268 sentences corrected out of 495 reviewed, about half of the text.
- The city guides have no translated sections.
- Useful phrases in list form are not translated.