zhhz

Self-contained Simplified/Traditional Chinese converter — pure-Rust reimplementation of OpenCC. CLI, Rust library, npm (WASM), and a native Python binding — all backed by the same engine and the same embedded OpenCC dictionaries.

npm PyPI crates.io JSR License Build status

What is zhhz?

zhhz (zh hanzi — 转换汉字, “convert Chinese characters”, a palindrome) is a pure-Rust reimplementation of OpenCC. It converts between Simplified and Traditional Chinese across the same six variants OpenCC supports (Mainland, Taiwan, Hong Kong, Japan old/new), and identifies which variant a piece of text is written in.

All OpenCC dictionaries are embedded at compile time via include_str!, so a single ~1.86 MB static binary (588 KB xz-compressed / 803 KB gzip / 663 KB zstd) carries everything it needs — no runtime data fetch, no separate dictionary directory.

At a glance

# CLI
echo '汉字' | zhhz                # 漢字 (default s2t)
echo '信息' | zhhz -c s2twp       # 資訊 (Taiwan phrases)
echo '鼠标' | zhhz -c s2twp       # 滑鼠

# Rust library
use zhhz::{Config, Converter};
let c = Converter::new(Config::S2t);
assert_eq!(c.convert("汉字"), "漢字");

# Node.js
import { convert, detect, Converter } from "zhhz";
console.log(convert("汉字", "s2t"));            // 漢字
console.log(detect("他去了西維珍尼亞州"));      // { region: "cn-hk", ... }

# Python
import zhhz
print(zhhz.convert("信息", "s2twp"))   # 資訊
print(zhhz.detect("汉字计算机软件"))  # Detection(region='cn-s', confidence=57)

Four distribution channels, one engine

Channel Audience Install s2t t2s
CLI (native) Shell, AI agents, scripts cargo install zhhz 88 MB/s 88 MB/s
Rust library Rust consumers [dependencies] zhhz = "0.7" same as CLI same as CLI
npm (WASM) Node.js / browsers npm install zhhz 63 MB/s 104 MB/s
Deno (WASM) Deno users npm:zhhz@… (live) 58 MB/s 108 MB/s
Python (PyO3) Python consumers pip install zhhz same as Rust same as Rust

Two numbers worth highlighting:

All five share the same Rust conversion core. Conversion output is byte-identical to the OpenCC reference CLI on all 538 supported-config cases. Full perf table: Benchmarks.

Designed for AI agents

zhhz is built first for AI agents (Claude, Cursor, custom LLM pipelines, batch jobs). The CLI is deliberately minimal:

What makes zhhz different

Where to go next