Repository navigation
1.16 part 3/18: Strings: ten languages, the Almanac's in files of their own - #174
epheterson wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Reviewer's GuideData structuresMove Almanac translation keys into dedicated per-language tables while retaining Home’s strings and adding the release’s other Home translations.
ImplementationDefine the shared rule for which prefixed strings Home retains, provide a merged translation-table reader, and make the file split reproducible and idempotent.
Add a key-wise three-way JSON merge driver that preserves OURS when a key-level conflict is detected.
TestsUpdate German informal-address checks to read the combined Home and Almanac tables and account for the Almanac scene note.
Check the offline BitTorrent explanation is present and understandable in all ten Home translations.
Check Community subtitle wording across languages and ensure Zimi has no separate category keys.
Check offline-readiness row order and the updated title across languages.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
9f6ca10 to
c03df64
Compare
efa0b56 to
25339b7
Compare
There was a problem hiding this comment.
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
| 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}) |
There was a problem hiding this comment.
🟠 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`.| write(path, {k: v for k, v in data.items() if k not in moved}) | ||
| write(apath, {**aldata, **moved}) |
There was a problem hiding this comment.
🟡 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.| 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}) |
There was a problem hiding this comment.
🟡 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.| @@ -0,0 +1,49 @@ | |||
| #!/usr/bin/env python3 | |||
| """Git merge driver for flat JSON string tables (zimi/static/i18n/*.json): three-way by key. | |||
There was a problem hiding this comment.
🟡 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`.| 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 |
There was a problem hiding this comment.
🟡 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.| moved = { | ||
| k: v | ||
| for k, v in data.items() | ||
| if is_almanac_key(k) and not home_needs(k, names) |
There was a problem hiding this comment.
🟡 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.c03df64 to
5add0fd
Compare
25339b7 to
c25f54c
Compare
Sourcery withdrew this approval because the latest commits introduced blocking findings.
5add0fd to
dcfb385
Compare
c25f54c to
1a57b2d
Compare
dcfb385 to
3e2591e
Compare
1a57b2d to
3bc60c8
Compare
|
Reviewed here; included in the release PR #189. |
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 thenot-a-releaselabel 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 prefixesalm_,tb_andref_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 asalm_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.scripts/i18n_split.py: the one rule for what Home needs (shell_names,home_needs,is_almanac_key) andwords(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: readswords("de")instead of one file, and addstb_scene_noteto the third-person allowlist (its "Ihre" is the clouds').tests/test_bt_env_var.py: assertsbt_why_offlineexists in all ten files, names noZIMI_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
scripts/i18n_split.pyfirst. Check thatshell_sources()covers every script and page Home can run, since a key it misses would show as a raw key name on Home.scripts/json_merge3.pymerge(): the conflict cases and that OURS is left untouched on exit 1.python3 -crather than reading them; the split is mechanical and rerunningpython3 scripts/i18n_split.pyon the base's files reproduces it.words(), the ten-filei18n/*.jsonglob, 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 nocat_zimikey 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.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:
Bug Fixes:
Enhancements:
Tests: