Open Chinese Convert (OpenCC, 開放中文轉換) is an open source project for high-quality conversion between Traditional Chinese, Simplified Chinese, Japanese Shinjitai, and regional wording across Mainland China, Taiwan, and Hong Kong. It provides dictionaries, a reusable library, conversion tools, and dictionary generation tools.
Open Chinese Convert(OpenCC,開放中文轉換) 是一個開源中文轉換項目,支持繁體中文、簡體中文、日文新字體,以及中國大陸、臺灣、香港等地區習慣用詞之間的高品質轉換,並提供詞典、可重用庫、轉換工具及詞典生成工具。
基於詞庫的確定性轉換,不使用大語言模型,結果穩定可預期,可離線快速運行。
Deterministic, dictionary-based conversion without large language models (LLMs): results are stable and predictable, and conversion runs fast and fully offline.
詞庫和函數庫可分離,允許自定義修改和擴展。
Dictionaries are decoupled from the library, allowing custom modification and extension.
嚴格區分簡繁對應與異體字對應關係,嚴格審校一簡對多繁詞條,OpenCC標準的用字原則爲「能分則不合」。
Strictly distinguishes Simplified-Traditional mappings from character variant mappings, with rigorously reviewed one-to-many Simplified-to-Traditional entries; the OpenCC standard follows the character usage principle of "separate whenever distinguishable".
支持中國大陸、臺灣、香港地區慣用異體字(如「裏」「裡」),以及習慣用詞轉換(如「鼠標」「滑鼠」)。
Supports conversion of preferred character variants (such as 「裏」/「裡」) and regional wording (such as 「鼠標」/「滑鼠」) for Mainland China, Taiwan, and Hong Kong.
詞庫內容均以官話(普通話、國語)詞彙爲基準,不支持語言之間的翻譯,例如官話與粵語、閩南語或日語之間的翻譯。
Dictionaries are based on Mandarin (Putonghua / Guoyu) vocabulary; translation between languages, such as between Mandarin and Cantonese, Southern Min, or Japanese, is not supported.
另外,有限支持日文新字體與舊字體之間的轉換。
In addition, conversion between Japanese Shinjitai (new character forms) and Kyujitai (old character forms) is supported to a limited extent.
The npm package supports Node.js >=20.17. The native addon is installed
through prebuilt @opencc/opencc-<platform>-<arch> packages covering macOS
(x64/arm64), Linux (x64/arm64), and Windows (x64). On platforms without a
prebuilt binary package, npm install builds from source with Bazel —
compiling the addon and regenerating the dictionaries — which requires a
C++ toolchain and network access; Bazel is found on PATH (bazel or
bazelisk) or fetched automatically via npx, and Bazel downloads its own
hermetic Python toolchain for the dictionary generation.
Bun and Deno can also use the npm package through their npm compatibility
support.
The Python CLI supports basic text conversion, --include-tofu-risk-dictionaries,
and --resource-zip. Diagnostic modes such as --inspect, --segmentation,
and --ambiguities still require the native OpenCC CLI.
When OpenCC is embedded in a server binary or self-contained application, the
JSON config can stay small while dictionary resources are loaded from explicit
resource directories:
FilesystemResourceProvider searches directories in order. Existing
SimpleConverter("s2t.json") and CLI behavior continue to use the config file
location, current directory, explicit paths, and installed OpenCC data directory
as before.
Unless otherwise noted, this section describes the native OpenCC CLI built from
the C++ toolchain. The Python and npm CLIs support basic file/stdin conversion
only, plus --include-tofu-risk-dictionaries; the Python CLI also supports
--resource-zip.
opencc --help
opencc_dict --help
Segmentation and Inspection Modes
OpenCC CLI supports two diagnostic modes that output JSON instead of converted text:
--segmentation — Output segmentation result only (no conversion):
--ambiguities — Convert while marking every output span whose dictionary
match is one-to-many (e.g. 文丑 may be either 文丑 or 文醜), as a stream
of JSONL records:
Record kinds: {"def"} defines the next source index (each distinct input
word is defined once, before its first reference); {"lit"} is a literal
run of unambiguous output; {"amb":{"t","s"}} is an ambiguous span whose
output text t (the default candidate) came from the source with index s;
the final {"end"} record carries stream totals. Concatenating every lit
and amb.t in order reproduces the plain conversion output exactly.
Streaming is bounded-memory regardless of input size or line length, and
positions are implicit in record order, so consumers can rebuild offsets in
their own string-index units. Single-value conversions (e.g. 头发 →
頭髮) are not flagged.
The record stream is a machine-readable contract: every emitted line is
valid JSON, and the final {"end"} record only appears when the whole
input was processed. Input containing invalid UTF-8 aborts the stream with
an error (unlike plain conversion, which is byte-transparent), and a
missing {"end"} record means the stream is incomplete.
These modes are useful for diagnosing conversion issues:
Use --segmentation to verify that the input is segmented as expected.
Use --inspect to see which conversion stage produces an unexpected result.
Use --ambiguities to locate one-to-many conversions and resolve each
deduplicated def source to its candidates.
Rules:
--segmentation, --inspect, and --ambiguities are mutually exclusive.
Official / Recommended Ports
The following ports are maintained within the OpenCC ecosystem and are generally up to date with current configuration and dictionary data.
OpenCC 現已支援外部 C++ 分詞插件。當前第一個插件為 opencc-jieba,
可通過 s2t_jieba.json、s2tw_jieba.json、s2hk_jieba.json、
s2twp_jieba.json、tw2sp_jieba.json 等插件配置啓用。
OpenCC now supports external C++ segmentation plugins. The first plugin is
opencc-jieba, which can be enabled through plugin-backed configs such as
s2t_jieba.json, s2tw_jieba.json, s2hk_jieba.json,
s2twp_jieba.json, and tw2sp_jieba.json.
Windows 下插件必須與宿主 OpenCC 二進位使用 ABI 相容的工具鏈/執行時構建;MSVC 與 MinGW 產物不支援混用。
Notes:
The plugin mechanism is currently experimental.
The jieba plugin is optional and is not required by the Python package or
the Node.js package. Since 1.4.1, top-level CMake builds on macOS (including
Homebrew) enable the plugin by default (BUILD_OPENCC_JIEBA_PLUGIN=ON);
other platforms and subproject builds keep it disabled by default.
opencc-jieba additionally depends on cppjieba and its dictionary
resources. These dependencies are only needed when building or distributing
the plugin itself.
The plugin ABI may still change before the next formal OpenCC release and
should not yet be treated as stable.
We expect to treat the plugin ABI as stable starting with the next formal
OpenCC release.
On Windows, plugins must be built with an ABI-compatible toolchain/runtime as
the host OpenCC binary. Mixing MSVC-built hosts with MinGW-built plugins, or
the reverse, is unsupported.
Build 編譯
Build with CMake
Linux & macOS
g++ 4.6+ or clang 3.2+ is required.
make
Windows Visual Studio:
build.cmd
Build with Bazel
bazel build //:opencc
Test 測試
Linux & macOS
make test
Windows Visual Studio:
test.cmd
Test with Bazel
bazel test --test_output=all //src/... //data/... //python/... //test/...
Since 1.4.2, the Windows binaries — the executables in the portable CLI zip
and the opencc.node / opencc-jieba.dll shipped in the win32-x64 npm
packages — are Authenticode-signed.
This program uses free code signing provided by
SignPath.io, and a free code signing
certificate by the SignPath Foundation.
Privacy policy 隱私政策:OpenCC 為離線的文字轉換程式庫與命令列工具,除非
使用者、安裝者或操作者明確要求,否則不會將任何資訊傳輸至其他網路系統。
This program will not transfer any information to other networked systems
unless specifically requested by the user or the person installing or
operating it.