Skip to content

Add PocketBook SDIC (.dic) writer plugin#708

Merged
ilius merged 15 commits into
ilius:masterfrom
lomereiter:sdic_writer
Mar 24, 2026
Merged

Add PocketBook SDIC (.dic) writer plugin#708
ilius merged 15 commits into
ilius:masterfrom
lomereiter:sdic_writer

Conversation

@lomereiter

@lomereiter lomereiter commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Background:

This PR ports the Go writer to Python. (I'm not aware of any need for the reader, but if anyone asks, it'd be rather easy to add later.)

There's an open question regarding the sorting order. PocketBook .dic files include a section which determines how keys are collated. Ideally it would be generated from PyICU automatically, or respect --sort-encoding, but this would be quite an undertaking. So for now the sorting is done internally by the plugin. Any ideas of how to improve this are very welcome.

LLM usage disclaimer:

  • planning of the port was fully done by GPT 5.4 (two rather long prompts)
  • implementation was fully done by Claude Opus 4.6 (one simple prompt just pointing to the plan file)
  • I am only doing the manual testing
  • I included copilot-instructions.md and the plan file in the commit for transparency, but happy to remove them, just ask

Implement write support for PocketBook SDIC binary dictionary format

Features:
- Entries sorted by collated key (accent-folded, uppercased)
- Duplicate headword merging with configurable separator
- zlib-compressed data blocks with binary search for optimal packing
- Block limits: max 100 entries, 65531 raw bytes, 4097 compressed target
- Built-in English metadata defaults (collates, morphems, keyboard)
- Configurable metadata via write options (metadata_dir, collates_path, etc.)
- Skips binary resource entries with aggregated warning
- Uses only primary term (alternates/synonyms ignored)

Write options:
- metadata_dir: directory with collates.txt, morphems.txt, keyboard.txt
- collates_path, keyboard_path, morphems_path: individual overrides
- merge_separator: separator for duplicate headword merging (default: <br>)

Tests: 50 unit tests + 13 integration tests covering collation, body
encoding, block packing, section building, header construction,
sorting, merging, HTML preservation, and multi-block dictionaries.

Co-authored-by: Copilot <[email protected]>
@ilius ilius added the Feature label Mar 24, 2026
Comment thread tests/g_pocketbook_sdic_test.py Outdated
Comment thread tests/g_pocketbook_sdic_test.py Outdated
Comment thread pyglossary/plugins/pocketbook_sdic/writer.py Outdated
@lomereiter lomereiter requested a review from ilius March 24, 2026 08:48
Comment thread tests/g_pocketbook_sdic_test.py Outdated
Comment thread tests/g_pocketbook_sdic_test.py Outdated
@ilius ilius merged commit 70f22f1 into ilius:master Mar 24, 2026
10 checks passed
@ilius

ilius commented Mar 24, 2026

Copy link
Copy Markdown
Owner

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants