# Language packs

HooLang looks words up in language packs. A pack is a folder of plain files. Only English with
Czech meanings (`en`, `en-cs`) ships in the app, in `shared/src/commonMain/composeResources/files/packs/`;
every other pack is downloaded on request and published from the `HooLangWeb` repository (see
"On-demand download").

- A **study pack** belongs to one study language (`de`). It knows the word forms of the language:
  which dictionary forms (lemmas) a form belongs to, the part of speech and the pronunciation.
- A **meaning pack** belongs to one pair (`de-cs`, `de-en`). It maps a dictionary form to its meanings
  in the meaning language.

Adding a pair means running the converters below on new source files. No converter and no app code
is specific to one language, with two historical exceptions: English is still reduced to dictionary
forms by suffix rules in the app (`OfflineDictionary.lookupEnglish`), and until version 1.1 the
built-in Spanish forms table came from hand-written rules in `../freedict/build-language-index.py`.
Every downloadable pack, Spanish included since 2026-11-23, is built from Wiktionary data only.

## Layout

```
packs/
  de/                    study pack
    pack.json
    forms/<shard>.tsv    form -> pronunciation, lemmas          (Kaikki.org, CC BY-SA 4.0)
    ipa/<shard>.tsv      form -> pronunciations                 (ipa-dict, own licence)
  de-cs/                 meaning pack
    pack.json
    meanings/<shard>.tsv headword -> meanings                   (WikDict, CC BY-SA 4.0)
    curated.json         hand-written meanings of grammar words and frequent words (HooLang; kept
                         in curated/<pair>.json and copied into the pack)
  en/irregular.json      irregular English forms                (HooLang, English only)
```

Every table is split into shard files by the first character of the key (`packlib.shard_of`, the
same as `shardOf` in the app's `PackSource.kt`). Each source keeps its own table, so each licence
covers only its own files.

- **Latin tables** (the default): 27 files, `a.tsv` to `z.tsv` and `other.tsv` for everything else
  (`ä`, `ö`, `ü`, digits, the odd Greek or Cyrillic key), written even when empty.
- **Letter tables** (since 2026-11-24, for languages written in Greek or Cyrillic): when more than half
  of the keys start with a character of the Greek (U+0370–U+03FF), Greek Extended (U+1F00–U+1FFF),
  Cyrillic or Cyrillic Supplement (U+0400–U+052F) blocks, each such first character gets its own file
  named `u` + its code point in four lower-case hex digits: `u03b1.tsv` for α, `u03ac.tsv` for ά,
  `u0436.tsv` for ж. `a.tsv` to `z.tsv` and `other.tsv` hold the rest as before. Only non-empty
  files are written, and the table records the scheme in `pack.json`
  (`"tableDetails": {"forms": {"shards": "letters", ...}}`), which is what makes the app use it.
  The names are plain ASCII and differ in more than letter case, so they are safe on every file
  system and in the catalog. Latin tables do not carry the field, so their files and bytes are the
  same as before; apps older than this scheme never list Greek or Cyrillic packs.

## Tables

A table is UTF-8 text, one row per line, fields separated by a tab, lines ended by `\n`:

```
key <TAB> field <TAB> field ...
```

- The key is the normalised word: NFC, trimmed, lower case, `’` written as `'`, `‐` and `‑` as `-`
  (`packlib.normalize`, the same as `wordKey` in the app).
- Rows are **sorted by the UTF-8 bytes of the key** and keys are unique. The app does not parse a
  shard; it binary-searches the bytes (`LineTable`), so a table costs its file size in memory.
- Trailing empty fields are dropped. Fields never contain a tab or a line break.

| Table | Fields after the key | Example |
| --- | --- | --- |
| `forms` | pronunciation, lemmas | `ging<TAB>[ɡɪŋ]<TAB>gehen/verb` |
| `ipa` | pronunciations joined by ` · ` | `hauses<TAB>[ˈhaʊ̯zəs] · [ˈhaʊ̯zɛs]` |
| `meanings` | one field per meaning, best first | `haus<TAB>dům<TAB>budova` |

### `forms`

- Pronunciation: IPA in square brackets, or empty. The app then falls back to the `ipa` table.
- Lemmas: `lemma/pos` items separated by `|`. The lemma keeps its spelling (`Haus`), the app
  normalises it to find the meanings. The part of speech is wiktextract's code (`noun`, `verb`,
  `adj`, `adv`, `pron`, `prep`, `conj`, `det`, `article`, `num`, `intj`, `particle`, `name`, ...),
  for nouns followed by the gender when it is unambiguous: `noun.m`, `noun.f`, `noun.n`.
- A word that is a dictionary form lists itself first (`haus<TAB>[haʊ̯s]<TAB>Haus/noun.n`); the
  other lemmas follow, the ones with more senses in Wiktionary first. At most four lemmas.
- Rows written by the older converter (`../freedict/`) have a bare headword without a part of
  speech, or an empty lemma field when the form is its own headword. The app reads both.
- Later fields are reserved (a frequency rank is planned) and ignored by the app.

### `pack.json`

```json
{
  "format": 2,
  "kind": "study",
  "language": "de",
  "meaningLanguage": "cs",
  "tables": ["forms", "ipa"],
  "curated": false,
  "tableDetails": {
    "forms": { "rows": 0, "source": { "name": "...", "url": "...", "licence": "...", "snapshot": "..." } }
  }
}
```

`meaningLanguage` is present in meaning packs only. The app reads `tables` (a table that is not
listed is never opened) and `curated`; the rest documents where the data comes from. Format 1 was
the layout of version 1.0.0 (JSON shards, no manifest).

## Building the packs

All commands run from `third-party/`; `P` is the folder the packs are written to: `../shared/src/commonMain/composeResources/files/packs` for the built-in English packs, a work folder for the downloadable ones, which are then published with `build-catalog.py`. `KEY` is the catalog signing key, `~/androidworkspace/keystore/hoolang/pack-catalog-signing.pem` (never in a repository).
The sources and their licences are recorded in the `NOTICE.txt` of each converter's folder.

```
# German study pack: forms from Wiktionary, then pronunciations for the forms that have none
python3 kaikki/build-study-pack.py kaikki.org-dictionary-German.jsonl.gz de $P/de --snapshot 2026-10-30
python3 ipa-dict/build-index.py de de.txt $P/de --only-missing

# Meaning packs, one command per pair. German, Polish and English have a hand-written list in
# curated/xx-cs.json: grammar words, abbreviations, contractions, compounds of the Wikipedia samples WikDict
# lacks, and since 2026-11-24 the frequent words whose WikDict order puts a rare sense first (well: studna,
# born: medvěd, seine: Seina, Menschen: jednodolarovka, pl jest...). The list is copied as it is; the app shows
# it first for the tapped form only, so inflected forms (areas, became, größte) have entries of their own.
mkdir -p $P/de-cs && cp language-packs/curated/de-cs.json $P/de-cs/curated.json
python3 wikdict/build-meaning-pack.py de-cs.sqlite3 de cs $P/de-cs --snapshot 2026-06-23
mkdir -p $P/pl-cs && cp language-packs/curated/pl-cs.json $P/pl-cs/curated.json
python3 wikdict/build-meaning-pack.py pl-cs.sqlite3 pl cs $P/pl-cs --snapshot 2026-06-23
python3 wikdict/build-meaning-pack.py de-en.sqlite3 de en $P/de-en --snapshot 2026-06-23
cp language-packs/curated/en-cs.json $P/en-cs/curated.json
python3 wikdict/build-meaning-pack.py wikdict/wikdict-en-cs-2026-06-23.sqlite3.xz en cs $P/en-cs \
    --snapshot 2026-06-23 --irregular wikdict/irregular-en.txt $P/en

# Publish the downloadable packs (copies to the web repository, writes the app's and the web's
# catalog, signs the web one)
python3 language-packs/build-catalog.py --version 2026-11-20 --key $KEY \
    --web ~/webworkspace/HooLangWeb/public/data/packs \
    --catalog ../shared/src/commonMain/composeResources/files/pack-catalog.json $P/de $P/de-cs $P/de-en

# Italian (2026-11-22): forms from Kaikki, meanings from WikDict it-cs; the Italian headwords WikDict
# lacks come from the Czech and Italian Wiktionary editions, grammar words from curated/it-cs.json.
# --merge keeps the other packs of the catalog as they are.
python3 kaikki/build-study-pack.py kaikki.org-dictionary-Italian.jsonl.gz it $P/it --snapshot 2026-10-30
python3 kaikki/build-meaning-supplement.py it cs it-cs-supplement.tsv \
    --glosses cs-extract.jsonl.gz --translations it-extract.jsonl.gz
mkdir -p $P/it-cs && cp language-packs/curated/it-cs.json $P/it-cs/curated.json
python3 wikdict/build-meaning-pack.py it-cs.sqlite3 it cs $P/it-cs --snapshot 2026-06-23 \
    --supplement it-cs-supplement.tsv "Wiktionary (cs, it editions) via Kaikki.org" \
    https://kaikki.org/dictionary/rawdata.html 2026-10-30 --curated language-packs/curated/it-cs.json
python3 language-packs/build-catalog.py --version 2026-11-22 --merge --key $KEY \
    --web ~/webworkspace/HooLangWeb/public/data/packs \
    --catalog ../shared/src/commonMain/composeResources/files/pack-catalog.json $P/it $P/it-cs

# Spanish (2026-11-23), the same way as Italian; the supplement comes from the Czech Wiktionary only.
# It replaces the built-in FreeDict data of versions 1.0 to 1.1 (built with
# freedict/build-language-index.py and, for German, build-v1-fallback.py; neither is used any more).
python3 kaikki/build-study-pack.py kaikki.org-dictionary-Spanish.jsonl.gz es $P/es --snapshot 2026-10-30
python3 kaikki/build-meaning-supplement.py es cs es-cs-supplement.tsv --glosses cs-extract.jsonl.gz
mkdir -p $P/es-cs && cp language-packs/curated/es-cs.json $P/es-cs/curated.json
python3 wikdict/build-meaning-pack.py es-cs.sqlite3 es cs $P/es-cs --snapshot 2026-06-23 \
    --supplement es-cs-supplement.tsv "Wiktionary (cs edition) via Kaikki.org" \
    https://kaikki.org/dictionary/rawdata.html 2026-10-30 --curated language-packs/curated/es-cs.json
python3 language-packs/build-catalog.py --version 2026-11-23 --merge --key $KEY \
    --web ~/webworkspace/HooLangWeb/public/data/packs \
    --catalog ../shared/src/commonMain/composeResources/files/pack-catalog.json $P/es $P/es-cs

# French and Portuguese with Czech meanings: WikDict fr-cs and pt-cs, no supplement, and the
# hand-written list. Since 2026-11-24 the curated lists of es-cs, it-cs, fr-cs and pt-cs also hold
# frequent content words the sources lack or order badly (each meaning backed by two sources: WikDict
# either way, Wiktionary, DeepL in a sample sentence), most of them keyed by dictionary form, so
# these four X -> Czech pairs are built with --curated: the curated meanings then lead the rows of their
# dictionary forms and reach all forms (presenta -> presentar). de-cs, pl-cs and en-cs stay without it, because
# there forms inherited a homonym's meaning (gemeint -> mého); the forms that differ have entries of their own.
for l in fr pt; do
  mkdir -p $P/$l-cs && cp language-packs/curated/$l-cs.json $P/$l-cs/curated.json
  python3 wikdict/build-meaning-pack.py $l-cs.sqlite3 $l cs $P/$l-cs --snapshot 2026-06-23 \
      --curated language-packs/curated/$l-cs.json
  python3 language-packs/measure-coverage.py $P/$l $P/$l-cs wikipedia-$l.txt
done

# Czech (2026-11-24): the study language is Czech, the meanings are English. W is the work folder
# with the sources and sample/wikipedia-cs.txt. Forms from Kaikki,
# meanings from WikDict cs-en; the headwords WikDict lacks come from the English Wiktionary (its Czech
# entries explained in English) and the English translations of the Czech Wiktionary; grammar words and
# abbreviations from curated/cs-en.json. The app looks a Czech word up whole, then without the prefix
# nej, then without ne, and measure-coverage.py follows the same order with --strip-prefixes.
# --curated puts the meanings of the hand-written list first in the rows of their headwords: the app shows
# a tapped form's own curated meanings first, but reaches a dictionary form's meanings only through the
# meanings table, so a dictionary form in the list (rád, celý) leads for all its forms (ráda, celou).
W=/Volumes/T5/hoolang-czech; P=$W/packs
python3 kaikki/build-study-pack.py kaikki.org-dictionary-Czech.jsonl.gz cs $P/cs --snapshot 2026-10-30
python3 kaikki/build-meaning-supplement.py cs en cs-en-supplement.tsv \
    --glosses kaikki.org-dictionary-Czech.jsonl.gz --translations cs-extract.jsonl.gz
mkdir -p $P/cs-en && cp language-packs/curated/cs-en.json $P/cs-en/curated.json
python3 wikdict/build-meaning-pack.py cs-en.sqlite3 cs en $P/cs-en --snapshot 2026-06-23 \
    --supplement cs-en-supplement.tsv "Wiktionary (en, cs editions) via Kaikki.org" \
    https://kaikki.org/dictionary/rawdata.html 2026-10-30 --curated language-packs/curated/cs-en.json
python3 language-packs/measure-coverage.py --strip-prefixes nej,ne $P/cs $P/cs-en $W/sample/wikipedia-cs.txt
python3 language-packs/build-catalog.py --version 2026-11-24 --merge --key $KEY \
    --web ~/webworkspace/HooLangWeb/public/data/packs \
    --catalog ../shared/src/commonMain/composeResources/files/pack-catalog.json $P/cs $P/cs-en

# Czech into German, Spanish, French, Italian, Polish and Portuguese (2026-11-24): the same study pack
# `cs`; three meaning sources, in this order of priority per headword:
#   1. curated/cs-xx.json, written by hand for HooLang (grammar words, pronouns, relative pronouns, prepositions,
#      abbreviations, units, titles, frequent words the sources lack or get wrong); it always wins, also for
#      the forms of a dictionary form it lists (--curated, as for cs-en). In all seven lists a sense that needs
#      the reflexive se or si is marked "(se)" or "(si)" when the form also has a sense without it
#      (těší: pleases | nice to meet you (těší mě) | looks forward (se)); senses are ordered by usage;
#   2. WikDict cs-xx (https://download.wikdict.com/dictionaries/sqlite/2/cs-xx.sqlite3);
#   3. headwords WikDict lacks: first the translations of the Czech Wiktionary entries (cs-extract.jsonl.gz from
#      https://kaikki.org/dictionary/downloads/cs/), then the xx-cs WikDict database read backwards
#      (wikdict/build-reverse-supplement.py: a Czech word gets the single-word headwords it translates, best
#      score first, at most four; xx-cs.sqlite3 from the same WikDict folder).
# W holds the sources (cs-xx.sqlite3, xx-cs.sqlite3, cs-extract.jsonl.gz) and sample/wikipedia-cs.txt. A pair
# below 85 % of the running words of the sample does not go into the catalog.
for l in de es fr it pl pt; do
  python3 kaikki/build-meaning-supplement.py cs $l cs-$l-supplement.tsv --translations cs-extract.jsonl.gz
  python3 wikdict/build-reverse-supplement.py $l-cs.sqlite3 cs-$l-reverse.tsv --first cs-$l-supplement.tsv
  mkdir -p $P/cs-$l && cp language-packs/curated/cs-$l.json $P/cs-$l/curated.json
  python3 wikdict/build-meaning-pack.py cs-$l.sqlite3 cs $l $P/cs-$l --snapshot 2026-06-23 \
      --supplement cs-$l-reverse.tsv "Wiktionary (cs edition) via Kaikki.org, WikDict $l-cs reversed" \
      https://kaikki.org/dictionary/rawdata.html 2026-10-30 --curated language-packs/curated/cs-$l.json
  python3 language-packs/measure-coverage.py --strip-prefixes nej,ne $P/cs $P/cs-$l $W/sample/wikipedia-cs.txt
done
python3 language-packs/build-catalog.py --version 2026-11-24 --merge --key $KEY \
    --web ~/webworkspace/HooLangWeb/public/data/packs \
    --catalog ../shared/src/commonMain/composeResources/files/pack-catalog.json \
    $P/cs-de $P/cs-es $P/cs-fr $P/cs-it $P/cs-pl $P/cs-pt

# Review of the first meanings (2026-11-24): the meanings the app shows first for the 600 most frequent words
# of the sample and every word of the Czech starter texts, one column per pair, with the app's Czech lookup
# (curated first, forms table, nej/ne). Corrections go into curated/cs-xx.json; after a change the seven
# meaning packs are rebuilt with the commands above (exFAT on T5 leaves ._* files: delete them first) and
# published in one catalog run.
python3 language-packs/review-frequent-words.py $P/cs $W/sample/wikipedia-cs.txt \
    $P/cs-en $P/cs-de $P/cs-es $P/cs-fr $P/cs-it $P/cs-pl $P/cs-pt --top 600 --texts $W/starters/cs-*.txt
find $P -name '._*' -delete
python3 language-packs/build-catalog.py --version 2026-11-24 --merge --key $KEY \
    --web ~/webworkspace/HooLangWeb/public/data/packs \
    --catalog ../shared/src/commonMain/composeResources/files/pack-catalog.json \
    $P/cs-en $P/cs-de $P/cs-es $P/cs-fr $P/cs-it $P/cs-pl $P/cs-pt

# Greek (2026-11-24), both directions with Czech: the study pack el, the meaning packs el-cs and cs-el. Greek
# keys keep the tonos (οδός); the app lower-cases a tapped word, which writes a final sigma as ς on every
# platform (ΟΔΌΣ -> οδός). The forms and meanings tables of el and el-cs are letter tables (see "Layout").
# el-cs: WikDict el-cs; headwords WikDict lacks come from the Czech Wiktionary (Czech glosses of Greek words),
# the Greek Wiktionary (its Czech translations, el-extract.jsonl.gz from https://kaikki.org/dictionary/downloads/el/)
# and WikDict cs-el read backwards; articles, pronouns, prepositions with article (στο, στην), particles,
# abbreviations and frequent verb forms the forms table lacks come from curated/el-cs.json. --curated is used:
# its 239 headwords lead their forms too (μελέτες: studie, not etuda); the forms whose lemma list wrongly
# names an article (με, σε, σου, σας, εμάς) have entries of their own. cs-el is built like cs-it.
# W holds the sources and the sample, 60 general articles (the 30 of the other languages and 30 more):
python3 language-packs/fetch-wikipedia-sample.py --cache $W/cache --titles $W/titles-el.txt el $W/sample/wikipedia-el.txt
python3 kaikki/build-study-pack.py kaikki.org-dictionary-Greek.jsonl.gz el $P/el --snapshot 2026-10-30
python3 kaikki/build-meaning-supplement.py el cs el-cs-supplement.tsv \
    --glosses cs-extract.jsonl.gz --translations el-extract.jsonl.gz
python3 wikdict/build-reverse-supplement.py cs-el.sqlite3 el-cs-reverse.tsv --first el-cs-supplement.tsv
mkdir -p $P/el-cs && cp language-packs/curated/el-cs.json $P/el-cs/curated.json
python3 wikdict/build-meaning-pack.py el-cs.sqlite3 el cs $P/el-cs --snapshot 2026-06-23 \
    --supplement el-cs-reverse.tsv "Wiktionary (cs, el editions) via Kaikki.org, WikDict cs-el reversed" \
    https://kaikki.org/dictionary/rawdata.html 2026-10-30 --curated language-packs/curated/el-cs.json
python3 kaikki/build-meaning-supplement.py cs el cs-el-supplement.tsv --translations cs-extract.jsonl.gz
python3 wikdict/build-reverse-supplement.py el-cs.sqlite3 cs-el-reverse.tsv --first cs-el-supplement.tsv
mkdir -p $P/cs-el && cp language-packs/curated/cs-el.json $P/cs-el/curated.json
python3 wikdict/build-meaning-pack.py cs-el.sqlite3 cs el $P/cs-el --snapshot 2026-06-23 \
    --supplement cs-el-reverse.tsv "Wiktionary (cs edition) via Kaikki.org, WikDict el-cs reversed" \
    https://kaikki.org/dictionary/rawdata.html 2026-10-30 --curated language-packs/curated/cs-el.json
python3 language-packs/measure-coverage.py $P/el $P/el-cs $W/sample/wikipedia-el.txt
python3 language-packs/measure-coverage.py --strip-prefixes nej,ne $P/cs $P/cs-el $W/sample/wikipedia-cs.txt

# Dutch and Swedish (2026-11-24), both directions with Czech. W holds the sources (Kaikki Dutch and Swedish,
# WikDict nl-cs, cs-nl, sv-cs, cs-sv, cs-extract.jsonl.gz) and the samples; the Czech study pack `cs` is the one above.
# Study packs: forms and IPA from Kaikki. Swedish has IPA for only 1.5 % of its forms, so the words without one get the
# first transcription of ipa-dict's sv.txt (Folkets lexikon, CC BY-SA 2.5), as for German.
# nl-cs, sv-cs: WikDict, the Czech Wiktionary glosses as supplement and curated/xx-cs.json copied as it is, without
# --curated: a curated key that is also another word's dictionary form (bladeren, wegen, en, man, lever) would lead
# all forms of that word (weegt: silnice, levern: žít), so the forms that need a curated meaning have entries of their
# own. cs-nl, cs-sv: the same three sources as the other cs-xx pairs, with --curated.
# --replace takes curated/<pair>-replace.json: rows that replace a wrong source row instead of only coming before it
# (nl b: ano, men: tebe; sv mm: lahodný; cs nákladní: duur/flott, i: dan; an empty list removes the row).
for l in nl sv; do
  k=$( [ $l = nl ] && echo Dutch || echo Swedish )
  python3 kaikki/build-study-pack.py kaikki.org-dictionary-$k.jsonl.gz $l $P/$l --snapshot 2026-10-30
  [ $l = sv ] && python3 ipa-dict/build-index.py sv sv.txt $P/sv --only-missing
  python3 kaikki/build-meaning-supplement.py $l cs $l-cs-supplement.tsv --glosses cs-extract.jsonl.gz
  mkdir -p $P/$l-cs && cp language-packs/curated/$l-cs.json $P/$l-cs/curated.json
  python3 wikdict/build-meaning-pack.py $l-cs.sqlite3 $l cs $P/$l-cs --snapshot 2026-06-23 \
      --supplement $l-cs-supplement.tsv "Wiktionary (cs edition) via Kaikki.org" \
      https://kaikki.org/dictionary/rawdata.html 2026-10-30 --replace language-packs/curated/$l-cs-replace.json
  python3 kaikki/build-meaning-supplement.py cs $l cs-$l-supplement.tsv --translations cs-extract.jsonl.gz
  python3 wikdict/build-reverse-supplement.py $l-cs.sqlite3 cs-$l-reverse.tsv --first cs-$l-supplement.tsv
  mkdir -p $P/cs-$l && cp language-packs/curated/cs-$l.json $P/cs-$l/curated.json
  python3 wikdict/build-meaning-pack.py cs-$l.sqlite3 cs $l $P/cs-$l --snapshot 2026-06-23 \
      --supplement cs-$l-reverse.tsv "Wiktionary (cs edition) via Kaikki.org, WikDict $l-cs reversed" \
      https://kaikki.org/dictionary/rawdata.html 2026-10-30 --curated language-packs/curated/cs-$l.json \
      --replace language-packs/curated/cs-$l-replace.json
  python3 language-packs/measure-coverage.py $P/$l $P/$l-cs $W/sample/wikipedia-$l.txt
  python3 language-packs/measure-coverage.py --strip-prefixes nej,ne $P/cs $P/cs-$l $W/sample/wikipedia-cs.txt
done

# Tests of the converters, and coverage of a text
python3 -m unittest discover language-packs
python3 language-packs/measure-coverage.py $P/de $P/de-cs ../shared/src/commonMain/composeResources/files/starters/de-*.txt
```

# Cleaning of meanings (since 2026-11-24). Every converter that writes meanings (build-meaning-pack.py,
# build-meaning-supplement.py, build-reverse-supplement.py) runs each meaning through packlib.clean_meaning:
# wiki markup ([[target|label]] -> label, [[target]] -> target, stray [[ ]] {{...}} ''), HTML entities
# (decoded; a meaning that keeps an unknown one or a cut-off one such as "é&l" is dropped) and mojibake
# (UTF-8 read as Latin-1 or Windows-1252, repaired, dropped when it does not decode). Correct text is never
# changed. Curated lists are not cleaned: a curated meaning with markup, an entity or mojibake stops the build.
# Packs built before that step are cleaned in place (row order, shard files and names stay; a row that loses
# all meanings is dropped; pack.json changes only when the row count does; a second run changes nothing):
python3 language-packs/clean-pack-meanings.py $P/de-cs $P/cs-el ...

The converters are deterministic: the same source files give the same bytes.

## On-demand download

Only English with Czech meanings is part of the app. Every other dictionary (German, Spanish,
French, Italian, Polish, Portuguese, German with English meanings) is downloaded from
https://hoolang.app/data/packs/ in Settings › Dictionaries (Slovníky), in the first-run guide or when a text in
the language is added or opened, and can be removed again. Versions 1.0 to 1.1 had smaller German
and Spanish dictionaries built in; since 1.2 they are downloads like the others.

- **Publishing.** `build-catalog.py` copies the pack folders to
  `HooLangWeb/public/data/packs/<id>/<version>/` and writes the catalog from the same files (the
  path, size and SHA-256 of every file) twice: into the app (`files/pack-catalog.json`) and to the
  web (`catalog.json`), and signs the web copy (`catalog.json.sig`). Versions are dates; a published
  version folder is never changed or deleted, because apps built with an older catalog still
  download from it. Every file must stay below 25 MiB (Cloudflare).
- **Updates without an app release.** Pushing a new version of a pack to HooLangWeb `main` is enough:
  the catalog's `sequence` grows with every publication, and an app takes the web catalog when its
  signature is valid and its sequence is higher than that of the catalog it has (the built-in one or
  a signed one saved earlier). Older signed catalogs are refused, so nobody can roll an app back.
  The next app release carries the same catalog built in.
- **When the app checks.** Once per run: on start when at least one pack is installed, and when the
  dictionaries screen opens. It first fetches `catalog.json.sig` (72 bytes) and fetches the catalog
  only when the signature differs from the saved one. The verified catalog is kept in
  `packs/catalog/` and verified again on every start.
- **Automatic updates.** An installed pack whose catalog lists a newer version is updated without
  asking: always on Wi-Fi or another unmetered network, on mobile data (and in Low Data Mode on
  iOS) only when the update downloads at most 4 MiB; larger ones wait for Wi-Fi or the Update
  button. A failed automatic update stays quiet and is tried again on the next start.
- **Only changed files.** An update compares every file of the new version with the installed copy
  (size and SHA-256) and downloads only the files that differ; the others are copied from the
  installed version. Packs are split into shards per table (27, or one per letter for Greek and
  Cyrillic), so a fix of a few words costs a few hundred kilobytes, not the whole dictionary.
- **What the app trusts.** The catalog compiled into it, and a newer catalog signed with the
  HooLang catalog key (ECDSA P-256 with SHA-256; the public key is pinned in `CatalogSignature.kt`
  and is `catalog-signing-key.pub.pem` here). The server tells nothing else: the address is built
  from the pack id and version, each file must have exactly the size and the SHA-256 of the catalog,
  and the catalog itself is validated (format, ids, versions, plain relative paths, at most 25 MiB
  per file and 64 MiB per pack). Losing the private key only stops updates without an app release;
  a new key needs an app release that pins it.
- **Transport.** HTTPS to `https://hoolang.app/data/packs/` only; no redirect is followed, only status
  200 counts, the connection and each read have time limits, a body longer than the expected size is
  cut off. Only data files are fetched, no code.
- **Storage.** Private app storage (`filesDir/packs`, `Application Support/packs`, left out of
  backups). A download is assembled in `packs/incoming/<id>/` that the dictionary never reads. Only
  when every file has passed does the folder move to `packs/installed/<id>/` in one step; the previous
  version is moved aside first and deleted after. A failed, cancelled or interrupted download leaves
  the previous state untouched, and leftovers are deleted at start.
- **Reading.** `LayeredPacks`: when a pack is installed, all its files come from the installed
  folder; otherwise the built-in pack of the same id is used (only English has one). Removing a
  pack leaves no dictionary for the pair.
- **Saved words** keep their meanings, which are copied into the database when a word is saved.
- **Debug builds only** (Android): writing a server address to `files/debug-pack-server.txt` of the app
  (`adb shell run-as cz.hoos.hoolang sh -c 'echo http://10.0.2.2:8765/ > files/debug-pack-server.txt'`)
  makes the downloader use that server (cleartext only to 10.0.2.2, only in the debug manifest).
  The server must serve the web folder including `catalog.json` and `catalog.json.sig`. A release
  build never reads the file.
- **Licence screen.** The notice lists every source, including those of the downloadable packs.
