Skip to content

Add support for custom dictionaries - #19

Open
Zenous07 wants to merge 1 commit into
pgaskin:masterfrom
Zenous07:custom-dictionaries
Open

Add support for custom dictionaries#19
Zenous07 wants to merge 1 commit into
pgaskin:masterfrom
Zenous07:custom-dictionaries

Conversation

@Zenous07

Copy link
Copy Markdown

What this does

Adds support for registering custom dictionaries in lithiumpatch, on top of the existing built-in ones (edgedict, webster1913). Users can now convert any dictionary they own into a simple JSON format and plug it into the build — no need to touch the core patching logic.

This is implemented as a new dict/custom package that:

  • Embeds one or more JSON dictionary files using //go:embed.
  • Registers each one with the existing dict.Register(name, priority, parseFunc) API — the same mechanism the built-in dictionaries already use.
  • Requires only a single blank import in main.go (_ "github.com/pgaskin/lithiumpatch/dict/custom") to activate.

How to use it

  1. Convert your source dictionary (StarDict, CSV, or anything else) into a JSON array matching the existing dict.Entry struct — each entry has Terms, Name, MeaningGroups (with Meanings[].Text etc.), and Source. No changes were made to dict.Entry itself.
  2. Place the resulting .json file in dict/custom/.
  3. Add a //go:embed + dict.Register(...) block for it in dict/custom/custom.go — a couple of lines per dictionary.
  4. Build as usual: go run . app/Lithium_0.24.5.apk. The dictionary shows up in the reader's lookup feature alongside the built-in ones.

Full details, including a worked StarDict conversion example and a CSV conversion example, are documented in the new "Custom Dictionaries" section added to the README.

Backward compatibility

This change is fully additive and backward-compatible:

  • No existing dictionary code, structs, or registration logic was modified.
  • Built-in dictionaries (edgedict, webster1913) continue to work exactly as before if the user doesn't touch dict/custom.
  • If a user doesn't add any custom dictionaries or doesn't import the custom package, behavior is identical to the current master branch.

Testing

Built and tested locally with go run . app/Lithium_0.24.5.apk. Confirmed the custom dictionary registered via dict/custom appears correctly in the app's word-lookup UI alongside the built-in dictionaries, with no regressions to existing dictionary behavior.

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