Skip to content

A dictionary in Translate: meanings under a word, downloaded with its model (discussion #400) - #415

Merged
Joost-8 merged 7 commits into
mainfrom
feat-dictionary
Dec 4, 2026
Merged

Joost-8 merged 7 commits into
mainfrom
feat-dictionary

Conversation

@Joost-8

@Joost-8 Joost-8 commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Do not merge before the dictionary files are uploaded (node scripts/dictionary-mirror.mjs <build folder>, a new public release dictionary-1 on FineNotes-templates). Until they are, a download that includes a dictionary fails on the dictionary. The translation itself still works, and the dictionary is not offered again in that session.

What changed

The third item of discussion #400: a dictionary for selected words, beside the translator.

  • Translating a single word or a short phrase (up to 3 words) shows its meanings under the translation, in the list the AI notes already use. An inflected form follows its dictionary form one step: "liep" shows "singular past indicative of lopen", then what lopen means.
  • There is one offline dictionary per translator language (54), built from Wiktionary (English edition, via kaikki.org's wiktextract, CC BY-SA 4.0). Sizes: English 35 MB, Spanish 8, Russian 6, German and French 5, Dutch 2, most others under 2. 119 MB for all 54.
  • A language's dictionary downloads together with its translation model, and the card says so in one line: "With the Dutch dictionary for single words". The fine print credits Wiktionary next to Mozilla. Someone who already has the model is offered the dictionary alone under a single-word translation, once per session.
  • The file format is chunked: an index, then gzipped pieces of about 96 K characters. A lookup unzips one piece (six are kept), so the iPad never holds a whole dictionary's text. The file's bytes are let go after 2 minutes unused, like the translation worker.
  • Meanings come in a reader's order: an inflection and its head word's senses of the same part of speech first, then the word as written before other spellings ("set" before "SET"). Names and "Initialism of …" go last.
  • When a download card doesn't fit the Translate window, the window grows (FloatingWindow.growBy). The size the user set is kept.
  • Scripts: dictionary-build.mjs (raw extract → packs + src/translate/dictionary-catalog.ts; --version), dictionary-pack.mjs (the writer), and dictionary-mirror.mjs (uploads; never replaces a released file).
  • Strings: 5 keys, in English and 42 languages.

Proof

  • npm run gates: all 11 steps pass. check.mjs --changed (all 391 scenes): no finding in the Translate scenes; its 7 groups are the ones the nightly already reports.
  • 22 tests in tests/translate/dictionary.test.ts. One reads what the real writer writes, across many chunks.
  • Real data, through the plugin's own module: words in 8 languages looked up in the built files (huizen, liep, vergankelijk, Häuser, Schadenfreude, ging, maisons, efímero, fue, 房子, 朋友, 家, ありがとう, дома, ran, running, set). Each found its meanings, in 0.1 to 4 ms.
  • That check found a build bug that had dropped about 3 in 100 entries, among them Schadenfreude, vergankelijk and 房子: the build read a nested lang_code. Fixed and rebuilt.
  • Gallery: 4 new scenes, light and dark (meanings, the card with the dictionary, the dictionary alone, a card without one). Review page: https://claude.ai/artifact/BK57eFJnN6oCZcAnjQYM3Y
  • Reviewed by the reviewer agent; its 8 findings are fixed.

Test on the device

Possible only once the files are uploaded.

  1. Settings › Models: delete Dutch ↔ English if it is there. Select one Dutch word in a PDF (for example "huizen") and Translate. The card should say "With the Dutch dictionary for single words". Download.
  2. The word's translation shows, with meanings under it ("noun: plural of huis", "noun: a house, home…"). Select other single words and Translate each: the meanings should come at once.
  3. Choose Into = Dutch (the same language): the meanings alone show, with no translation.

Not verified

  • Nothing on the iPad: no download, no memory use, no speed. The files are not uploaded, so the download cannot run.
  • The 42 languages' strings are the worker's, not checked by native speakers.
  • Meanings and parts of speech are always English ("noun: house"), whatever the app's language.
  • The gallery scenes are in this worktree only. They go into the dev repo when this merges (they import code main does not have yet).

🤖 Generated with Claude Code

Joost-8 and others added 7 commits December 3, 2026 19:23
…ed with the model (#400)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ader's order; the window grows for its card (#400)

- Packs are FNDICT2 files: an index, then gzipped chunks of about 96 K
  characters; a lookup unzips one chunk (an LRU keeps six), so the 127 MB
  English text never sits in memory whole.
- The build read the first "lang_code" in a raw line, often an
  etymology's or a translation's, and dropped many entries
  (Schadenfreude, vergankelijk, 房子): it now reads the entry's own.
  A line is a form of another word only when its first sense says so.
- Meanings: an inflection and its head word's senses of the same part of
  speech first, the word as written before other spellings, names and
  initialisms last.
- A download card the result well cannot hold makes the window taller
  (FloatingWindow.growBy, not saved).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The mirror never replaces a released file: one already there must be
  the same (size, GitHub's SHA-256) or the run stops. The release is
  dictionary-<DICTIONARY_VERSION>; the build takes --version.
- A dictionary that fails to download no longer holds up the
  translation it came with; it is not offered again this session.
- The dictionary alone is offered once a session per language, not
  under every word.
- The pack is loaded once however many lookups wait (a shared promise)
  and let go after IDLE_RELEASE_MS, like the worker.
- The window grows for the actions under a card too.
- "With the {language} dictionary" (not "a English").
- A test reads what the real writer (dictionary-pack.mjs) writes.
- Release notes describe the chunked format and every change made.
- Roots and lone syllables are not words; adv_phrase and circumpos get
  names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Joost-8
Joost-8 marked this pull request as ready for review December 4, 2026 01:50
@Joost-8
Joost-8 merged commit f6af80f into main Dec 4, 2026
1 check passed
@Joost-8
Joost-8 deleted the feat-dictionary branch December 4, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant