Skip to content

feat: add Zhuyin (Bopomofo) input for Traditional Chinese - #553

Closed
CatTimothy wants to merge 5 commits into
FossifyOrg:mainfrom
CatTimothy:feat/zhuyin-input
Closed

CatTimothy wants to merge 5 commits into
FossifyOrg:mainfrom
CatTimothy:feat/zhuyin-input

Conversation

@CatTimothy

Copy link
Copy Markdown

Note

Draft until a maintainer is OK with this: #193 isn't labeled help wanted yet, and this PR adds JUnit 4 as a testImplementation dependency (the repo had no unit tests). Happy to drop the tests or split the PR if you prefer.

Type of change(s)

  • Bug fix
  • Feature / enhancement
  • Infrastructure / tooling (CI, build, deps, tests)
  • Documentation

What changed and why

Adds a Zhuyin (Bopomofo) keyboard for Traditional Chinese with phrase conversion, as requested in #193. Converting Zhuyin needs a language model, so this ports McBopomofo (MIT) to pure Kotlin. There is no NDK or new runtime dependency, so F-Droid builds are unaffected.

  • Layout: a new keys_letters_chinese_zhuyin.xml in the standard Daqian (大千) layout, with digits on long-press and full-width , and 。. The language is listed as 中文 (注音).
  • Engine (zhuyin/):
    • Kotlin port of McBopomofo's Gramambular2 reading grid and Viterbi walk.
    • Bopomofo syllable composition.
    • A lexicon of McBopomofo's phrase data, about 6 MB, kept in memory as raw bytes and binary searched. It's loaded in the background only while Zhuyin is the active language.
  • Input:
    • The composition is shown as composing text, with a scrollable candidate bar above the keys.
    • Space adds the first tone or commits.
    • Tapping a candidate commits.
    • Leading phrases are committed automatically once no longer phrase can change them, so the composition stays short. The result is the same as converting the whole sentence at once.
    • Password and non-text fields fall back to plain symbol input.
  • Next phrase suggestions: after a commit, the bar suggests how the text may continue (e.g. 嗎 after 你好). The data is derived from the same lexicon (associated.txt, about 1 MB).
  • scripts/zhuyin/build_lexicon.py regenerates both assets from McBopomofo's data.txt. Licenses and the source commit are in assets/zhuyin/.

Tests performed

  • 38 JVM unit tests (./gradlew :app:testFossDebugUnitTest), including ports of McBopomofo's reading grid tests. detekt and lint pass with no new issues.
  • Manually tested on an API 37 emulator:
    • Typing, converting, picking candidates, backspace, enter, punctuation, and the suggestions.
    • Moving the cursor away and switching apps or languages.
    • Password fields.
    • All themes, and the largest font size.

Before & after preview

Screenshots to follow.

Closes the following issue(s)

Checklist

  • I read the contribution guidelines.
  • I manually tested my changes on device/emulator (if applicable).
  • I updated the "Unreleased" section in CHANGELOG.md (if applicable).
  • I have self-reviewed my pull request (no typos, formatting errors, etc.).
  • I understand every change in this pull request.

🤖 Generated with Claude Code

CatTimothy and others added 5 commits December 4, 2026 23:12
Adds a standard Dachen (大千) Bopomofo layout with full-width punctuation
on the bottom row. This only types Zhuyin symbols for now; phrase
conversion will follow in a separate change.

Refs: FossifyOrg#193

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds a pure-Kotlin port of McBopomofo's Gramambular2 reading grid
(Viterbi walk over a phrase lattice) together with McBopomofo's phrase
data, both MIT licensed. The lexicon is kept as raw sorted bytes and
searched with binary search, so it needs no parsing at load time.

The engine is not wired into the keyboard yet.

- zhuyin/BopomofoSyllable: standard layout syllable composer
- zhuyin/Lexicon: lexicon lookups over assets/zhuyin/lexicon.txt
- zhuyin/ReadingGrid: Gramambular2 port
- zhuyin/ZhuyinEngine: composing, candidates, backspace and commit
- scripts/zhuyin/build_lexicon.py: regenerates the lexicon asset
- JVM unit tests, including tests ported from reading_grid_test.cpp

Refs: FossifyOrg#193

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wires ZhuyinEngine into the keyboard when the Zhuyin layout is active:

- typed Bopomofo is shown as composing text and converted to phrases
- a candidate bar over the toolbar lets the user pick other phrases
- space adds the first tone, or commits when no syllable is pending
- enter, punctuation and other keys commit the composition first
- backspace edits the composition before deleting committed text
- password fields keep typing raw Bopomofo symbols
- the lexicon loads in the background and is released when switching
  to another language

Refs: FossifyOrg#193

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Tapping a candidate applies it and commits the composition, like
  pressing enter.
- Phrases are committed automatically once they are settled: no phrase
  in the grid crosses the boundary after them, and the lexicon has no
  longer reading that starts before the boundary and could still cross
  it once more syllables are typed. Because unigram scores add up along
  the path, the best conversion before a settled boundary can no longer
  change, so the committed text is the same as converting the whole
  sentence at once (e.g. ㄍㄠ ㄎㄜ ㄐㄧˋ still becomes 高科技). In practice
  the composition stays at about 1-5 syllables.

- Lexicon.hasReadingsStartingWith: binary-searched reading prefixes
- ReadingGrid.isCrossed: whether any node crosses a boundary
- tests for equivalence with full conversion and for 高科技

Refs: FossifyOrg#193

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After text is committed, the candidate bar shows endings of lexicon
phrases that start with its last one or two characters, e.g. 嗎 and 像
after 你好. Tapping a suggestion commits it and suggests again; typing
Bopomofo, other keys or moving the cursor hides the suggestions.

The suggestions (assets/zhuyin/associated.txt, ~1 MB) are derived from
the McBopomofo lexicon by build_lexicon.py. The sorted line lookup is
shared with Lexicon through the new SortedLines class.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fossifybot

fossifybot Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Fossify accepts code contributions only for open issues labeled help wanted. This pull request does not meet that requirement or one of the documented exceptions, so it is being closed without review. Please read the contribution guidelines before starting work.

@fossifybot fossifybot Bot closed this Dec 4, 2026
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.

Add Chewing 注音 layout to Fossify

1 participant