Skip to content

1.16 part 3/18: Strings: ten languages, the Almanac's in files of their own - #174

Closed
epheterson wants to merge 1 commit into
line/1.16.0-02-server-readingfrom
line/1.16.0-03-strings
Closed

epheterson wants to merge 1 commit into
line/1.16.0-02-server-readingfrom
line/1.16.0-03-strings

Conversation

@epheterson

@epheterson epheterson commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Part 3 of 18 of Zimi 1.16.0: Strings: ten languages, the Almanac's in files of their own. Base: line/1.16.0-02-server-reading (part 2); the diff shows only this part's files. The PR carries the not-a-release label and the version stays 1.15.7, so merging it cuts no release. Merge in order (1 to 17, then 18) with a merge commit, not a squash.

What this is

The Almanac's strings move out of Home's translation files into files of their own, and the release's new strings arrive in all ten languages. Home no longer downloads about 1,170 keys it never shows; the Almanac loads its own table when it opens. The part is almost entirely data: two small scripts and four tests carry the logic.

What changes

  • zimi/static/i18n/<lang>.json (ten files): the keys with prefixes alm_, tb_ and ref_ leave, unless Home's own code names them (a quoted name in a non-Almanac script is either the key or the front of a family such as alm_shower_ plus the shower's name). Each file goes from 3,699 keys to 2,688.
  • zimi/static/i18n/almanac/<lang>.json (ten new files): 1,697 keys each, the moved 1,174 plus 523 new Almanac and Almanac-tables keys. Key sets are identical across the ten languages in both folders.
  • 174 new keys in Home's files for the release's other surfaces (add-ons, offline readiness, sentences, capabilities, apps, voices, PDF, backup, older versions, maps). Eleven keys are removed.
  • scripts/i18n_split.py: the one rule for what Home needs (shell_names, home_needs, is_almanac_key) and words(lang), which returns Home's and the Almanac's table merged. Run as a script it performs the split and is idempotent.
  • scripts/json_merge3.py: a git merge driver for flat JSON tables, three-way by key. Keys either side added are kept, a one-sided change wins, a key both sides changed differently exits 1 so git reports a conflict. It exists because ten files of one key per line conflict on every concurrent edit.
  • tests/test_german_du.py: reads words("de") instead of one file, and adds tb_scene_note to the third-person allowlist (its "Ihre" is the clouds').
  • tests/test_bt_env_var.py: asserts bt_why_offline exists in all ten files, names no ZIMI_ variable and says HTTP.
  • tests/test_community_copy.py, tests/test_offline_order.py: the Community subtitle wording and the Offline Readiness row order and title in every language.

How to review

  • Read scripts/i18n_split.py first. Check that shell_sources() covers every script and page Home can run, since a key it misses would show as a raw key name on Home.
  • Read scripts/json_merge3.py merge(): the conflict cases and that OURS is left untouched on exit 1.
  • Risk: a moved key that Home or a non-Almanac app page reads at run time without a quoted literal (a key built from pieces with a prefix other than the quoted front). The tests below guard the quoted case only.
  • Skip: the twenty JSON files. Compare key sets with python3 -c rather than reading them; the split is mechanical and rerunning python3 scripts/i18n_split.py on the base's files reproduces it.
  • Rides here: the four tests are in this part because they read the new file layout (words(), the ten-file i18n/*.json glob, the new keys) and first pass at this tip. tests/test_i18n_split.py, which guards the split itself, lands in part 4 because it also reads Home's scripts at their part 4 state.

Tests

  • tests/test_german_du.py: German addresses the reader as "du" across the merged Home and Almanac table.
  • tests/test_community_copy.py: the Community subtitle names users and the Kiwix catalog in every language, and no cat_zimi key remains.
  • tests/test_bt_env_var.py: the offline BitTorrent explanation is in words in every language.
  • tests/test_offline_order.py: the useful offline rows lead and Create's add-ons come last; the title is no longer the old English wording in any language.
  • No test here needs a browser.

Summary by Sourcery

Separate Almanac translations from Home’s language tables and add multilingual copy updates, merge tooling, and validation for the new layout.

New Features:

  • Separate Almanac translations into dedicated files for all ten supported languages while expanding Home translations for the release surfaces.

Bug Fixes:

  • Clarify Community and Offline Readiness copy across all languages and ensure offline BitTorrent messaging is language-independent of internal variable names.

Enhancements:

  • Add shared translation loading and an idempotent split utility for Home and Almanac strings.
  • Add a key-aware three-way JSON merge driver to reduce conflicts in translation tables.
  • Reorder Offline Readiness entries so essential resources precede Create add-ons.
  • Update German informal-address validation to cover the combined Home and Almanac translation tables.

Tests:

  • Add coverage for multilingual Community copy, offline wording, Offline Readiness ordering and titles, and the reorganized German translation tables.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@epheterson epheterson added the not-a-release Ships nothing; CI skips the version check label Nov 23, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Move Almanac translation keys into dedicated per-language tables while retaining Home’s strings and adding the release’s other Home translations.

  • zimi/static/i18n/almanac/ar.json L1-1699
  • zimi/static/i18n/almanac/de.json L1-1699
  • zimi/static/i18n/almanac/en.json L1-1699
  • zimi/static/i18n/almanac/es.json L1-1699
  • zimi/static/i18n/almanac/fr.json L1-1699
  • zimi/static/i18n/almanac/he.json L1-1699
  • zimi/static/i18n/almanac/hi.json L1-1699
  • zimi/static/i18n/almanac/pt.json L1-1699
  • zimi/static/i18n/almanac/ru.json L1-1699
  • zimi/static/i18n/almanac/zh.json L1-1699
  • zimi/static/i18n/ar.json L2519-2689 (+25 small edits)
  • zimi/static/i18n/de.json L2519-2689 (+25 small edits)
  • zimi/static/i18n/en.json L2519-2689 (+25 small edits)
  • zimi/static/i18n/es.json L2519-2689 (+25 small edits)
  • zimi/static/i18n/fr.json L2519-2689 (+25 small edits)
  • zimi/static/i18n/he.json L2519-2689 (+25 small edits)
  • zimi/static/i18n/hi.json L2519-2689 (+25 small edits)
  • zimi/static/i18n/pt.json L2519-2689 (+25 small edits)
  • zimi/static/i18n/ru.json L2519-2689 (+25 small edits)
  • zimi/static/i18n/zh.json L2519-2689 (+25 small edits)

Implementation

Define the shared rule for which prefixed strings Home retains, provide a merged translation-table reader, and make the file split reproducible and idempotent.

  • scripts/i18n_split.py L1-93

Add a key-wise three-way JSON merge driver that preserves OURS when a key-level conflict is detected.

  • scripts/json_merge3.py L1-49

Tests

Update German informal-address checks to read the combined Home and Almanac tables and account for the Almanac scene note.

  • tests/test_german_du.py L6-34 (4 small edits)

Check the offline BitTorrent explanation is present and understandable in all ten Home translations.

  • tests/test_bt_env_var.py L87-100

Check Community subtitle wording across languages and ensure Zimi has no separate category keys.

  • tests/test_community_copy.py L1-36

Check offline-readiness row order and the updated title across languages.

  • tests/test_offline_order.py L1-52

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@epheterson epheterson mentioned this pull request Nov 23, 2026
@epheterson
epheterson force-pushed the line/1.16.0-02-server-reading branch from 9f6ca10 to c03df64 Compare November 23, 2026 10:07
@epheterson
epheterson force-pushed the line/1.16.0-03-strings branch from efa0b56 to 25339b7 Compare November 23, 2026 10:07
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Nov 23, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 6 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="scripts/i18n_split.py" line_range="85-87" />
<code_context>
+        moved = {
+            k: v
+            for k, v in data.items()
+            if is_almanac_key(k) and not home_needs(k, names)
+        }
+        write(path, {k: v for k, v in data.items() if k not in moved})
+        write(apath, {**aldata, **moved})
+        print(lang, "moved", len(moved))
</code_context>
<issue_to_address>
**Almanac labels show raw keys**

When the Almanac renders a prefixed key after the splitter moves it out of Home’s language file, `_loadI18n()` loads only Home’s table and `t()` searches `_i18n` and `_i18nFallback`, so the moved value is absent and the Almanac displays the raw key.

Load the Almanac translations into the lookup used by `t()` at runtime.

Also at `scripts/i18n_split.py:56`, `scripts/i18n_split.py:88`.
</issue_to_address>

### Comment 2
<location path="scripts/i18n_split.py" line_range="87-88" />
<code_context>
+            for k, v in data.items()
+            if is_almanac_key(k) and not home_needs(k, names)
+        }
+        write(path, {k: v for k, v in data.items() if k not in moved})
+        write(apath, {**aldata, **moved})
+        print(lang, "moved", len(moved))
+
</code_context>
<issue_to_address>
**Interrupted splits lose translations**

When the process stops after the Home file is rewritten but before the Almanac file is successfully written, `main()` removes the moved keys from Home before saving them to the Almanac table, so an interruption leaves the keys in neither file and a rerun cannot recover them.

Write the Almanac table atomically before removing the moved keys from Home, so an interruption leaves at least one copy.
</issue_to_address>

### Comment 3
<location path="scripts/i18n_split.py" line_range="87" />
<code_context>
+            for k, v in data.items()
+            if is_almanac_key(k) and not home_needs(k, names)
+        }
+        write(path, {k: v for k, v in data.items() if k not in moved})
+        write(apath, {**aldata, **moved})
+        print(lang, "moved", len(moved))
</code_context>
<issue_to_address>
**Concurrent edits get overwritten**

When a translator or another process updates either table while the split is running, `main()` writes the snapshot it read earlier over the language file, discarding translator edits made after that read; updating the Almanac file from a stale `aldata` snapshot can likewise erase concurrent additions.

Serialize the split with other table writers, or detect changes since each input was read and abort rather than overwrite them.
</issue_to_address>

### Comment 4
<location path="scripts/json_merge3.py" line_range="2" />
<code_context>
+#!/usr/bin/env python3
+"""Git merge driver for flat JSON string tables (zimi/static/i18n/*.json): three-way by key.
+
+    json_merge3.py BASE OURS THEIRS   (git's %O %A %B; the result is written to OURS)
</code_context>
<issue_to_address>
**Concurrent edits still conflict**

When branches edit the same translation JSON file concurrently, git does not invoke `json_merge3.py` because no attributes assign these files to a configured driver, so its per-key merge never runs and Git’s normal line merge reports conflicts.

Register `json_merge3.py` as a merge driver and assign the translation JSON files to it in `.gitattributes`.
</issue_to_address>

### Comment 5
<location path="tests/test_community_copy.py" line_range="34-36" />
<code_context>
+        assert "openZIM" not in d["cat_community_desc"], code
+
+
+def test_there_is_no_zimi_category():
+    for code, d in _all().items():
+        assert "cat_zimi" not in d and "cat_zimi_desc" not in d, code
</code_context>
<issue_to_address>
**Removed category still has no label**

When a library contains a ZIM whose category is still `zimi`, `BROWSE_CATEGORIES` still defines the `zimi` category with `cat_zimi`, while this change removes that translation key. If an installed or legacy ZIM still has category `zimi`, `_catDisplayName()` returns the missing key and Home displays `cat_zimi` instead of a category label.

Remove or migrate the remaining `zimi` category metadata and handle any existing `zimi` category values as Community before deleting its translations.
</issue_to_address>

### Comment 6
<location path="scripts/i18n_split.py" line_range="82-85" />
<code_context>
+        aldata = (
+            json.load(open(apath, encoding="utf-8")) if os.path.exists(apath) else {}
+        )
+        moved = {
+            k: v
+            for k, v in data.items()
+            if is_almanac_key(k) and not home_needs(k, names)
+        }
+        write(path, {k: v for k, v in data.items() if k not in moved})
</code_context>
<issue_to_address>
**New Home keys stay missing**

When a later shell change starts using a key that an earlier split left only in the Almanac table, and the splitter is rerun, `moved` is built only from `data.items()`, so a key already stored only in the Almanac file is never copied back to Home when a later shell source starts naming it; rerunning the splitter leaves Home without the translation and the shell displays the raw key.

Reconcile keys from both tables so every key matching `home_needs` is placed in Home and other Almanac keys remain in the Almanac table.
</issue_to_address>

Sourcery assessment

Approval pending. 6 findings to address first.

Blocking findings: scripts/i18n_split.py:87, scripts/i18n_split.py:88, scripts/i18n_split.py:87, scripts/json_merge3.py:2, tests/test_community_copy.py:36, and 1 more


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread scripts/i18n_split.py
Comment on lines +85 to +87
if is_almanac_key(k) and not home_needs(k, names)
}
write(path, {k: v for k, v in data.items() if k not in moved})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Almanac labels show raw keys

When the Almanac renders a prefixed key after the splitter moves it out of Home’s language file, _loadI18n() loads only Home’s table and t() searches _i18n and _i18nFallback, so the moved value is absent and the Almanac displays the raw key.

Load the Almanac translations into the lookup used by t() at runtime.

Also at scripts/i18n_split.py:56, scripts/i18n_split.py:88.

Prompt for AI agents
In `scripts/i18n_split.py` at lines 85-87:

**Almanac labels show raw keys**

When the Almanac renders a prefixed key after the splitter moves it out of Home’s language file, `_loadI18n()` loads only Home’s table and `t()` searches `_i18n` and `_i18nFallback`, so the moved value is absent and the Almanac displays the raw key.

Load the Almanac translations into the lookup used by `t()` at runtime.

Also at `scripts/i18n_split.py:56`, `scripts/i18n_split.py:88`.

Comment thread scripts/i18n_split.py
Comment on lines +87 to +88
write(path, {k: v for k, v in data.items() if k not in moved})
write(apath, {**aldata, **moved})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Interrupted splits lose translations

When the process stops after the Home file is rewritten but before the Almanac file is successfully written, main() removes the moved keys from Home before saving them to the Almanac table, so an interruption leaves the keys in neither file and a rerun cannot recover them.

Write the Almanac table atomically before removing the moved keys from Home, so an interruption leaves at least one copy.

Prompt for AI agents
In `scripts/i18n_split.py` at lines 87-88:

**Interrupted splits lose translations**

When the process stops after the Home file is rewritten but before the Almanac file is successfully written, `main()` removes the moved keys from Home before saving them to the Almanac table, so an interruption leaves the keys in neither file and a rerun cannot recover them.

Write the Almanac table atomically before removing the moved keys from Home, so an interruption leaves at least one copy.

Comment thread scripts/i18n_split.py
for k, v in data.items()
if is_almanac_key(k) and not home_needs(k, names)
}
write(path, {k: v for k, v in data.items() if k not in moved})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Concurrent edits get overwritten

When a translator or another process updates either table while the split is running, main() writes the snapshot it read earlier over the language file, discarding translator edits made after that read; updating the Almanac file from a stale aldata snapshot can likewise erase concurrent additions.

Serialize the split with other table writers, or detect changes since each input was read and abort rather than overwrite them.

Prompt for AI agents
In `scripts/i18n_split.py` at line 87:

**Concurrent edits get overwritten**

When a translator or another process updates either table while the split is running, `main()` writes the snapshot it read earlier over the language file, discarding translator edits made after that read; updating the Almanac file from a stale `aldata` snapshot can likewise erase concurrent additions.

Serialize the split with other table writers, or detect changes since each input was read and abort rather than overwrite them.

Comment thread scripts/json_merge3.py
@@ -0,0 +1,49 @@
#!/usr/bin/env python3
"""Git merge driver for flat JSON string tables (zimi/static/i18n/*.json): three-way by key.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Concurrent edits still conflict

When branches edit the same translation JSON file concurrently, git does not invoke json_merge3.py because no attributes assign these files to a configured driver, so its per-key merge never runs and Git’s normal line merge reports conflicts.

Register json_merge3.py as a merge driver and assign the translation JSON files to it in .gitattributes.

Prompt for AI agents
In `scripts/json_merge3.py` at line 2:

**Concurrent edits still conflict**

When branches edit the same translation JSON file concurrently, git does not invoke `json_merge3.py` because no attributes assign these files to a configured driver, so its per-key merge never runs and Git’s normal line merge reports conflicts.

Register `json_merge3.py` as a merge driver and assign the translation JSON files to it in `.gitattributes`.

Comment on lines +34 to +36
def test_there_is_no_zimi_category():
for code, d in _all().items():
assert "cat_zimi" not in d and "cat_zimi_desc" not in d, code

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Removed category still has no label

When a library contains a ZIM whose category is still zimi, BROWSE_CATEGORIES still defines the zimi category with cat_zimi, while this change removes that translation key. If an installed or legacy ZIM still has category zimi, _catDisplayName() returns the missing key and Home displays cat_zimi instead of a category label.

Remove or migrate the remaining zimi category metadata and handle any existing zimi category values as Community before deleting its translations.

Prompt for AI agents
In `tests/test_community_copy.py` at lines 34-36:

**Removed category still has no label**

When a library contains a ZIM whose category is still `zimi`, `BROWSE_CATEGORIES` still defines the `zimi` category with `cat_zimi`, while this change removes that translation key. If an installed or legacy ZIM still has category `zimi`, `_catDisplayName()` returns the missing key and Home displays `cat_zimi` instead of a category label.

Remove or migrate the remaining `zimi` category metadata and handle any existing `zimi` category values as Community before deleting its translations.

Comment thread scripts/i18n_split.py
Comment on lines +82 to +85
moved = {
k: v
for k, v in data.items()
if is_almanac_key(k) and not home_needs(k, names)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · New Home keys stay missing

When a later shell change starts using a key that an earlier split left only in the Almanac table, and the splitter is rerun, moved is built only from data.items(), so a key already stored only in the Almanac file is never copied back to Home when a later shell source starts naming it; rerunning the splitter leaves Home without the translation and the shell displays the raw key.

Reconcile keys from both tables so every key matching home_needs is placed in Home and other Almanac keys remain in the Almanac table.

Prompt for AI agents
In `scripts/i18n_split.py` at lines 82-85:

**New Home keys stay missing**

When a later shell change starts using a key that an earlier split left only in the Almanac table, and the splitter is rerun, `moved` is built only from `data.items()`, so a key already stored only in the Almanac file is never copied back to Home when a later shell source starts naming it; rerunning the splitter leaves Home without the translation and the shell displays the raw key.

Reconcile keys from both tables so every key matching `home_needs` is placed in Home and other Almanac keys remain in the Almanac table.

@epheterson
epheterson force-pushed the line/1.16.0-02-server-reading branch from c03df64 to 5add0fd Compare November 23, 2026 10:51
@epheterson
epheterson force-pushed the line/1.16.0-03-strings branch from 25339b7 to c25f54c Compare November 23, 2026 10:51
@sourcery-ai
sourcery-ai Bot dismissed their stale review November 23, 2026 10:52

Sourcery withdrew this approval because the latest commits introduced blocking findings.

@epheterson
epheterson force-pushed the line/1.16.0-02-server-reading branch from 5add0fd to dcfb385 Compare November 23, 2026 16:38
@epheterson
epheterson force-pushed the line/1.16.0-03-strings branch from c25f54c to 1a57b2d Compare November 23, 2026 16:38
@epheterson
epheterson force-pushed the line/1.16.0-02-server-reading branch from dcfb385 to 3e2591e Compare November 23, 2026 16:44
@epheterson
epheterson force-pushed the line/1.16.0-03-strings branch from 1a57b2d to 3bc60c8 Compare November 23, 2026 16:44
@epheterson

Copy link
Copy Markdown
Owner Author

Reviewed here; included in the release PR #189.

@epheterson epheterson closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

not-a-release Ships nothing; CI skips the version check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant