Skip to content

[ryoku] ocr: follow the session language and report missing data - #1042

Open
boyan0707 wants to merge 1 commit into
Ryoku-dev:mainfrom
boyan0707:ocr-language
Open

boyan0707 wants to merge 1 commit into
Ryoku-dev:mainfrom
boyan0707:ocr-language

Conversation

@boyan0707

@boyan0707 boyan0707 commented Dec 2, 2026 •

Copy link
Copy Markdown

What changed

ryoku-cmd-ocr called tesseract "$tmp" - without -l, so every capture ran the eng model: Chinese text came back as Latin-looking garbage. The 2>/dev/null on that same line hid the missing-model error, so a box without tesseract-data-chi_sim looked like a bad selection instead of a missing package.

This PR:

  • takes --lang LANG, then RYOKU_OCR_LANG, then the session locale (zh* to chi_sim, ja* to jpn, ko* to kor, else eng), always with eng appended for mixed captures;
  • checks the requested models against tesseract --list-langs: a missing primary model stops the run and names the package to install, a missing secondary one is dropped with a notice;
  • honours a user-level pack in ~/.local/share/ryoku-ocr/tessdata (or RYOKU_OCR_TESSDATA), which is the only way a box without root gets a language;
  • strips the spaces tesseract inserts between Han characters and before CJK punctuation, keeping the space in PDF 文件;
  • adds tesseract-data-chi_sim, chi_tra, jpn and kor to optdepends on ryoku-desktop, next to the existing hard tesseract and tesseract-data-eng;
  • adds one sentence to docs/ui-ux.md and a Fixed line to CHANGELOG.md.

Say if you would rather have the language live in shell.json or the Ryoshot settings page; the flag and the environment variable are the smallest surface that does not touch the Hub. The user-level tessdata directory is also easy to drop if you would rather keep packages as the only source of models.

Area

ryoku (the script and its docs) and release (the PKGBUILD).

How it was tested

On a running Ryoku box (Amaterasu v1.1.0, 0bf1174), driving the script the way Ryoshot does (ryoku-cmd-ocr --file <png>) against a 56 px render of 今天下午三点在三楼会议室开会:

call clipboard
before SR F=REZZIWNEA=
--lang chi_sim 今天下午三总在三楼会议室开会
--lang chi_sim+eng same
default en locale, English image Hello world 123
--lang chi_sim, no traineddata no copy; notice No OCR data for chi_sim (install tesseract-data-chi_sim)
--lang chi_tra, no traineddata no copy; notice names chi_tra
--nope usage notice, exit 2

The 总 for 点 is the chi_sim model, not the script. Clipboard and notifications were captured through a PATH shim first so the real session was untouched, then the script was run for real once to confirm the Ryoshot path end to end.

Checklist

  • One logical change, with a clear [area] scope: summary commit subject.
  • Matching CHANGELOG.md updated in the area I touched.
  • The git hooks pass locally; I did not use --no-verify.
  • Shell scripts pass bash -n (no Lua or QML in this change).
  • No duplicated config, no dead code, no commented-out code, no em-dash.
  • Docs updated: one sentence in docs/ui-ux.md.

Confidence Score: 5/5RetriggerView in Greptile

The PR appears safe to merge; all numbered previous findings are fixed.

Summary

OCR now follows the selected language, checks available models, combines user and system data, and removes extra spaces in Chinese text.

  • OCR captures use the language the user selects or the session uses.

Reviews (3) · Last reviewed commit: "[ryoku] ocr: follow the session language..." · Reviewed by Greptile

@neur0map neur0map left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔴 Changes requested — 0 critical and 1 major issue(s): see the inline comments and the walkthrough for fixes and an agent-ready prompt.

Comment thread ryoku/shell/scripts/ryoku-cmd-ocr Resolved
Comment thread ryoku/shell/scripts/ryoku-cmd-ocr Resolved
Comment thread ryoku/shell/scripts/ryoku-cmd-ocr Resolved
Comment thread ryoku/shell/scripts/ryoku-cmd-ocr Resolved
@neur0map

neur0map commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

🦊 mika's review

Incremental review: new commits since the last checkpoint.

Summary

  • Select OCR languages from overrides or the session locale.
  • Report missing models and support user-installed language data.
  • Clean Chinese OCR spacing and list optional language packs.

Change diagram

flowchart LR
  Input["Language override or locale"] --> OCR["ryoku-cmd-ocr"]
  Models["System and user language data"] --> OCR
  OCR --> Tesseract["Tesseract"]
  Tesseract --> Clipboard["Cleaned clipboard text"]
Loading

Estimated review effort: 2/5 · risk: medium

📁 Walkthrough details

ryoku/shell/scripts/ryoku-cmd-ocr

  • Selects language models from --lang, RYOKU_OCR_LANG, or the session locale, with English added for mixed captures.
  • Resolves system and user-installed models, reports missing data, and removes unwanted Chinese text spacing.
    • Added language argument parsing and locale mapping.
    • Combines user and system models in a temporary tessdata directory when needed.
    • Stops on a missing primary model and reports missing secondary models.
    • Cleans Han spacing and whitespace before CJK punctuation.

release/packages/ryoku-desktop/PKGBUILD

  • Lists Simplified Chinese, Traditional Chinese, Japanese, and Korean Tesseract data as optional dependencies.
    • Added four optional OCR language packages.

docs/ui-ux.md

  • Documents session-language OCR for Ryoshot text copying.
    • Updated the Ryoshot copy-text description.

CHANGELOG.md

  • Records the OCR language selection, missing-data notices, and Chinese spacing changes.
    • Added an OCR entry under fixes.

No actionable findings. Mika looked for bugs, security issues, and risks in the diff and came up empty on clear defects.

🛠 Deterministic checks run
  • shellcheck: not installed (skip)

⚠️ Security concerns: Traversal components in language names can cause links to be created outside the private tessdata directory.

🧪 No relevant tests detected in the diff.

🚦 Merge recommendation: changes_required


🦊 Generated by Mika — the Ryoku org's self-hosted AI code reviewer. Machine findings: verify before merging.

@neur0map neur0map added area:ryoku Ryoku project area type:bug A reported problem labels Dec 2, 2026
@neur0map

neur0map commented Dec 2, 2026

Copy link
Copy Markdown
Member

Thanks for the work here, this needs to target unstable-dev instead of main

Comment thread ryoku/shell/scripts/ryoku-cmd-ocr Resolved
Comment thread ryoku/shell/scripts/ryoku-cmd-ocr Resolved
@boyan0707

Copy link
Copy Markdown
Author

All four findings are addressed in 95c3707:

  • locale patterns: zh_TW*, zh_HK*, zh_MO* and zh* now cover the bare zh, ja and ko forms as well as the territory ones.
  • eng detection: matched as a complete +-delimited model ([[ +$lang+ == *+eng+* ]]), so beng no longer suppresses the English model.
  • mixed locations: every requested model is resolved where it exists (user pack first, then the system tessdata) and linked into one private --tessdata-dir. A user pack holding only chi_sim next to a system eng now works, and the directory is removed on exit.
  • literal matching: availability is a file test on the resolved path, not grep, so --lang en. reports missing data instead of silently matching eng.

Retested on the same box: LANG=zh_CN, bare LANG=zh, user pack with only chi_sim plus system eng, --lang beng, --lang en., no data at all, and the English default. bash -n and the git hooks pass.

@neur0map neur0map left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔍 Review findings — 1 blocking issue(s): see the inline comments and the walkthrough for details.

Comment thread ryoku/shell/scripts/ryoku-cmd-ocr Resolved
@neur0map
neur0map dismissed their stale review December 2, 2026 03:13

Blocking findings were addressed (verified at 95c3707cd6).

Comment thread ryoku/shell/scripts/ryoku-cmd-ocr Resolved
Comment thread ryoku/shell/scripts/ryoku-cmd-ocr Resolved
@boyan0707

Copy link
Copy Markdown
Author

The fifth finding is fixed in 1f0d6ad: RYOKU_OCR_LANG is read again before the locale fallback, so the order is --lang, then the environment, then the locale. It was dropped by my own rewrite of that block, which is why the earlier test run did not catch it.

Verified with RYOKU_OCR_LANG=chi_sim under LANG=en_US.UTF-8, and with RYOKU_OCR_LANG=eng --lang chi_sim (the flag wins).

@neur0map neur0map left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔴 Changes requested — 0 critical and 1 major issue(s): see the inline comments and the walkthrough for fixes and an agent-ready prompt.

Comment thread ryoku/shell/scripts/ryoku-cmd-ocr Resolved
Comment thread ryoku/shell/scripts/ryoku-cmd-ocr Resolved
ryoku-cmd-ocr called tesseract with no -l, so every capture ran the eng model.
Chinese text came back as Latin-looking garbage, and the 2>/dev/null on the same
line hid the missing-model error, which made a missing package look like a bad
selection.

The script now takes --lang, falls back to RYOKU_OCR_LANG and then to the session
locale (zh, ja, ko, else eng), always keeping eng for mixed captures. Requested
models are checked against tesseract --list-langs: a missing primary model stops
the run with the package name to install, and a user-level pack under
~/.local/share/ryoku-ocr/tessdata works without root. Chinese output loses the
spaces tesseract inserts between Han characters, so the copied text is usable
as-is.

tesseract-data-chi_sim, chi_tra, jpn and kor join optdepends on ryoku-desktop,
since only eng data ships by default.

Note: Fixed: OCR follows the session language and reports missing language data instead of copying garbage
@boyan0707

Copy link
Copy Markdown
Author

Both new findings are fixed in 8446ca5:

  • package-neutral notice: the missing-model notice no longer names an Arch package. It now reads No OCR data for chi_sim; install its tesseract language data, so Fedora and Void users get a usable instruction. The Arch names stay only in optdepends, where they belong.
  • relative RYOKU_OCR_TESSDATA: a relative override is made absolute against $PWD before the links are created, so the models resolve from the link directory. Verified by running from /tmp with RYOKU_OCR_TESSDATA=td2 next to a system eng.

@neur0map
neur0map dismissed their stale review December 2, 2026 03:23

Blocking findings were addressed (verified at 8446ca5544).

This branch has not been deployed

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

Labels

area:ryoku Ryoku project area type:bug A reported problem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants