Skip to main content

Conversion between Traditional and Simplified Chinese

Project description

Open Chinese Convert 開放中文轉換

CMake Bazel MSVC Node.js CI Python CI AppVeyor

latest packaged version(s)

Introduction 介紹

OpenCC

Open Chinese Convert (OpenCC, 開放中文轉換) is an opensource project for conversions between Traditional Chinese, Simplified Chinese and Japanese Kanji (Shinjitai). It supports character-level and phrase-level conversion, character variant conversion and regional idioms among Mainland China, Taiwan and Hong Kong. This is not translation tool between Mandarin and Cantonese, etc.

中文簡繁轉換開源項目,支持詞彙級別的轉換、異體字轉換和地區習慣用詞轉換(中國大陸、臺灣、香港、日本新字體)。不提供普通話與粵語的轉換。

Discussion (Telegram): https://t.me/open_chinese_convert

Features 特點

  • 嚴格區分「一簡對多繁」和「一簡對多異」。
  • 完全兼容異體字,可以實現動態替換。
  • 嚴格審校一簡對多繁詞條,原則爲「能分則不合」。
  • 支持中國大陸、臺灣、香港異體字和地區習慣用詞轉換,如「裏」「裡」、「鼠標」「滑鼠」。
  • 詞庫和函數庫完全分離,可以自由修改、導入、擴展。

Installation 安裝

Package Managers 包管理器

Prebuilt 預編譯

This is a Windows release intended for WinGet distribution. For details, see doc/windows-winget-release.md.

Usage 使用

Online 線上轉換

https://opencc.js.org/converter?config=s2t

Node.js

npm install opencc

import { OpenCC } from 'opencc';
async function main() {
  const converter: OpenCC = new OpenCC('s2t.json');
  const result: string = await converter.convertPromise('汉字');
  console.log(result);  // 漢字
}

See demo.js and ts-demo.ts.

Python

pip install opencc (Windows, Linux, macOS)

import opencc
converter = opencc.OpenCC('s2t.json')
converter.convert('汉字')  # 漢字

C++

#include "opencc.h"

int main() {
  const opencc::SimpleConverter converter("s2t.json");
  converter.Convert("汉字");  // 漢字
  return 0;
}

Full example with Bazel

C

#include "opencc.h"

int main() {
  opencc_t opencc = opencc_open("s2t.json");
  const char* input = "汉字";
  char* converted = opencc_convert_utf8(opencc, input, strlen(input));  // 漢字
  opencc_convert_utf8_free(converted);
  opencc_close(opencc);
  return 0;
}

Full Document 完整文檔

Command Line

  • opencc --help
  • opencc_dict --help

Other Ports (Unofficial)

Configurations 配置文件

預設配置文件

  • s2t.json Simplified Chinese to Traditional Chinese 簡體到繁體
  • t2s.json Traditional Chinese to Simplified Chinese 繁體到簡體
  • s2tw.json Simplified Chinese to Traditional Chinese (Taiwan Standard) 簡體到臺灣正體
  • tw2s.json Traditional Chinese (Taiwan Standard) to Simplified Chinese 臺灣正體到簡體
  • s2hk.json Simplified Chinese to Traditional Chinese (Hong Kong variant) 簡體到香港繁體
  • hk2s.json Traditional Chinese (Hong Kong variant) to Simplified Chinese 香港繁體到簡體
  • s2twp.json Simplified Chinese to Traditional Chinese (Taiwan Standard) with Taiwanese idiom 簡體到繁體(臺灣正體標準)並轉換爲臺灣常用詞彙
  • tw2sp.json Traditional Chinese (Taiwan Standard) to Simplified Chinese with Mainland Chinese idiom 繁體(臺灣正體標準)到簡體並轉換爲中國大陸常用詞彙
  • t2tw.json Traditional Chinese (OpenCC Standard) to Taiwan Standard 繁體(OpenCC 標準)到臺灣正體
  • hk2t.json Traditional Chinese (Hong Kong variant) to Traditional Chinese 香港繁體到繁體(OpenCC 標準)
  • t2hk.json Traditional Chinese (OpenCC Standard) to Hong Kong variant 繁體(OpenCC 標準)到香港繁體
  • t2jp.json Traditional Chinese Characters (Kyūjitai) to New Japanese Kanji (Shinjitai) 繁體(OpenCC 標準,舊字體)到日文新字體
  • jp2t.json New Japanese Kanji (Shinjitai) to Traditional Chinese Characters (Kyūjitai) 日文新字體到繁體(OpenCC 標準,舊字體)
  • tw2t.json Traditional Chinese (Taiwan standard) to Traditional Chinese 臺灣正體到繁體(OpenCC 標準)

指定配置文件

通过环境变量OPENCC_DATA_DIR加载指定路径下的配置文件

OPENCC_DATA_DIR=/path/to/your/config/dir opencc --help

Experimental Plugins 試驗性插件

OpenCC 現已支援外部 C++ 分詞插件。當前第一個插件為 opencc-jieba, 可通過 s2twp_jieba.jsontw2sp_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 s2twp_jieba.json and tw2sp_jieba.json.

注意:

  • 該插件機制目前仍為試驗性功能。
  • jieba 插件是可選組件,預設 OpenCC 構建、Python 套件和 Node.js 套件都不要求它。
  • opencc-jieba 額外依賴 cppjieba 及其配套詞典資源,這些依賴僅在構建或分發該插件時需要。
  • 在下一次正式發布版本之前,插件 ABI 仍可能發生變化,不應視為穩定介面。
  • 我們預計從下一次正式發布版本開始,將插件 ABI 視為穩定介面。
  • Windows 下插件必須與宿主 OpenCC 二進位使用 ABI 相容的工具鏈/執行時構建;MSVC 與 MinGW 產物不支援混用。

Notes:

  • The plugin mechanism is currently experimental.
  • The jieba plugin is optional and is not required for the default OpenCC build, Python package, or Node.js package.
  • 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/...

Benchmark 基準測試

make benchmark

Example results (from Github CI, commit ID 9e80d5d, 2026-04-16, CMake macos-latest):

-------------------------------------------------------------------------
Benchmark                               Time             CPU   Iterations
-------------------------------------------------------------------------
BM_Initialization/hk2s                868 us          868 us          665
BM_Initialization/hk2t                139 us          139 us         5059
BM_Initialization/jp2t                203 us          203 us         3448
BM_Initialization/s2hk              26201 us        26200 us           27
BM_Initialization/s2t               26385 us        26382 us           27
BM_Initialization/s2tw              27108 us        27108 us           27
BM_Initialization/s2twp             26446 us        26445 us           25
BM_Initialization/s2twp_jieba      142754 us       141974 us            5
BM_Initialization/t2hk               66.7 us         66.7 us        10519
BM_Initialization/t2jp                166 us          166 us         4215
BM_Initialization/t2s                 797 us          797 us          883
BM_Initialization/t2tw               58.1 us         58.1 us        12075
BM_Initialization/tw2s                845 us          845 us          831
BM_Initialization/tw2sp              1004 us         1004 us          697
BM_Initialization/tw2t               93.3 us         93.3 us         7492
BM_ConvertLongText/s2t                327 ms          327 ms            2 bytes_per_second=5.45069M/s
BM_ConvertLongText/s2twp              554 ms          554 ms            1 bytes_per_second=3.21299M/s
BM_ConvertLongText/s2twp_jieba        742 ms          741 ms            1 bytes_per_second=2.40096M/s
BM_Convert/s2t_100                  0.649 ms        0.649 ms         1083 bytes_per_second=6.15628M/s
BM_Convert/s2t_1000                  6.64 ms         6.64 ms          106 bytes_per_second=6.16118M/s
BM_Convert/s2t_10000                 68.1 ms         68.1 ms           10 bytes_per_second=6.14608M/s
BM_Convert/s2t_100000                 718 ms          717 ms            1 bytes_per_second=5.96785M/s
BM_Convert/s2twp_100                 1.20 ms         1.20 ms          552 bytes_per_second=3.32407M/s
BM_Convert/s2twp_1000                12.3 ms         12.3 ms           57 bytes_per_second=3.32311M/s
BM_Convert/s2twp_10000                126 ms          126 ms            6 bytes_per_second=3.31205M/s
BM_Convert/s2twp_100000              1296 ms         1296 ms            1 bytes_per_second=3.3027M/s
BM_Convert/s2twp_jieba_100           1.51 ms         1.49 ms          495 bytes_per_second=2.67698M/s
BM_Convert/s2twp_jieba_1000          15.0 ms         15.0 ms           48 bytes_per_second=2.72292M/s
BM_Convert/s2twp_jieba_10000          153 ms          153 ms            5 bytes_per_second=2.73681M/s
BM_Convert/s2twp_jieba_100000        1728 ms         1728 ms            1 bytes_per_second=2.47784M/s

Projects using OpenCC 使用 OpenCC 的項目

Please update if your project is using OpenCC.

License 許可協議

Apache License 2.0

Third Party Library 第三方庫

Change History 版本歷史

Links 相關鏈接

Contributors 貢獻者

Please feel free to update this list if you have contributed OpenCC.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opencc-1.3.0.tar.gz (11.7 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

opencc-1.3.0-cp314-cp314-manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.14

opencc-1.3.0-cp314-cp314-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

opencc-1.3.0-cp313-cp313-manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.13

opencc-1.3.0-cp313-cp313-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

opencc-1.3.0-cp312-cp312-manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12

opencc-1.3.0-cp312-cp312-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

opencc-1.3.0-cp311-cp311-manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.11

opencc-1.3.0-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

opencc-1.3.0-cp310-cp310-manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10

opencc-1.3.0-cp310-cp310-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file opencc-1.3.0.tar.gz.

File metadata

  • Download URL: opencc-1.3.0.tar.gz
  • Upload date:
  • Size: 11.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for opencc-1.3.0.tar.gz
Algorithm Hash digest
SHA256 bb7105c10ee90c9ba7493a099ac5e611ceab464b895c0584bd9ef304c10950fd
MD5 c22f7b67f91ed95278b483f374706062
BLAKE2b-256 e75a1ce3ff524f4e1735129b9b585af2fb9278eeb5880631e7c7c82dcf0fc089

See more details on using hashes here.

File details

Details for the file opencc-1.3.0-cp314-cp314-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencc-1.3.0-cp314-cp314-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae0b3c884b20ad3bfaf912b2e8d2aa5e2e29f0dc6916b1d3d86962064bc9db97
MD5 d735e9086f4854cba7712b988317706e
BLAKE2b-256 cb90afb6ae7583284db2516f0bf58a5ae5382f56804b27db34009ff0dbff4377

See more details on using hashes here.

File details

Details for the file opencc-1.3.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencc-1.3.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 10f369b744bb0cbcb9ff61f9f8aaaca82ecf368a860ddeae94416811d6dde144
MD5 24c975e1168f230b4f759c77bcfaf0dc
BLAKE2b-256 025dc9dacdf739d41f8b1ea95d5abdb165d2590b05819eddb231778bdc8e4314

See more details on using hashes here.

File details

Details for the file opencc-1.3.0-cp313-cp313-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencc-1.3.0-cp313-cp313-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b9f9d459d101888919b70e50a5dc8ad404cfee8c937e51011d618a380105899f
MD5 f227371dd8a5bea13dfaa53bac68f2b8
BLAKE2b-256 5c3176588f650e3d8e4dbb145a2a2508e3d7b1c7c5d6003a0ba33c91a06d9e1c

See more details on using hashes here.

File details

Details for the file opencc-1.3.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencc-1.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b77e2738d21250f7a87ca9b07c6e91f4af837f8c10d78303165856c982f57f0
MD5 67760cfaded8c1f8b3791b5bbe595132
BLAKE2b-256 9979aee359497424dc1f59fd40fa8cc8b0a077c36501bb20e4ca0f8df1cdc7dd

See more details on using hashes here.

File details

Details for the file opencc-1.3.0-cp312-cp312-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencc-1.3.0-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c53aba8f850e40dba07bafe94c81306fcdd43b33e3d84bf22690b28e308102c9
MD5 29b6c61cbc40e16da3284bd4bcf1553c
BLAKE2b-256 73d70a6bd4be95eddb4d55c6d16aeb9ef0f2d30d62324a9eaea0ad9017c2dd0b

See more details on using hashes here.

File details

Details for the file opencc-1.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencc-1.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 053fecbfee897fcbb767bed6803885641301cbd3b38c364eebf98f38659aa380
MD5 50d0b6d4742dd0de7e0bc2084b978048
BLAKE2b-256 89c2b4037bf4d2f1d70998265951afde4b79f5b7cb0f9a8ed5a2f4fc7f182176

See more details on using hashes here.

File details

Details for the file opencc-1.3.0-cp311-cp311-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencc-1.3.0-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fb4b6eb33cfffbdde8030c176980b601c4ce3007807e64a2f5c01ad35b0e3648
MD5 8886d4f897ee6d8dd68513cd0ad7af0c
BLAKE2b-256 63cda2582a0064a65a2542f4c0af0ab490d77a8b66c4420374cdaef8eefe6fae

See more details on using hashes here.

File details

Details for the file opencc-1.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencc-1.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5659b03a51e76c0cad5d5e479b25b26d983f799f952e3bef7089939c5593920
MD5 b0d1c94d6e8dd80215e2dfb6e4fe57f0
BLAKE2b-256 4be8cdcc7b10c9a5438b3216de19d623f0a3a27492f93089907330f890c24d72

See more details on using hashes here.

File details

Details for the file opencc-1.3.0-cp310-cp310-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencc-1.3.0-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e7a034415229b6b221c8cc9b9420992bdc52fdd5589324c459f6c8a12d0740cc
MD5 63086bfc449e79ad01882665881c70d1
BLAKE2b-256 6e264ba2e343b2391a4ec63434888fde6ecc7a30244fdb35a60730773547bd9e

See more details on using hashes here.

File details

Details for the file opencc-1.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencc-1.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5208caa4a1077908ab84aaa74c6c62bf6681b1193bf3f862ea643938e5734d5
MD5 e1212cfddde426944b8b09f426db8be2
BLAKE2b-256 a61dd09311f8166af9307805cc4f290ce3b55b412825f753190ef23666a188d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page