Skip to main content

Conversion between Traditional and Simplified Chinese

Project description

Open Chinese Convert 開放中文轉換

CMake Bazel MSVC Node.js CI Python CI AppVeyor

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 預編譯

Usage 使用

Online demo 線上轉換展示

Warning: This is NOT an API. You will be banned if you make calls programmatically.

https://opencc.byvoid.com/

Node.js

npm npm install opencc

JavaScript

const OpenCC = require('opencc');
const converter = new OpenCC('s2t.json');
converter.convertPromise("汉字").then(converted => {
  console.log(converted);  // 漢字
});

TypeScript

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;
}

Document 文檔: https://byvoid.github.io/OpenCC/

Command Line

  • opencc --help
  • opencc_dict --help
  • opencc_phrase_extract --help

Others (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 標準)

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):

1: ------------------------------------------------------------------
1: Benchmark                        Time             CPU   Iterations
1: ------------------------------------------------------------------
1: BM_Initialization/hk2s        1.56 ms         1.56 ms          442
1: BM_Initialization/hk2t       0.144 ms        0.144 ms         4878
1: BM_Initialization/jp2t       0.260 ms        0.260 ms         2604
1: BM_Initialization/s2hk        23.8 ms         23.8 ms           29
1: BM_Initialization/s2t         25.6 ms         25.6 ms           28
1: BM_Initialization/s2tw        24.0 ms         23.9 ms           30
1: BM_Initialization/s2twp       24.6 ms         24.6 ms           28
1: BM_Initialization/t2hk       0.052 ms        0.052 ms        12897
1: BM_Initialization/t2jp       0.141 ms        0.141 ms         5012
1: BM_Initialization/t2s         1.30 ms         1.30 ms          540
1: BM_Initialization/tw2s        1.39 ms         1.39 ms          529
1: BM_Initialization/tw2sp       1.69 ms         1.69 ms          426
1: BM_Initialization/tw2t       0.089 ms        0.089 ms         7707
1: BM_Convert2M                   582 ms          582 ms            1
1: BM_Convert/100                1.07 ms         1.07 ms          636
1: BM_Convert/1000               11.0 ms         11.0 ms           67
1: BM_Convert/10000               113 ms          113 ms            6
1: BM_Convert/100000             1176 ms         1176 ms            1

Projects using OpenCC 使用 OpenCC 的項目

Please update if your project is using OpenCC.

License 許可協議

Apache License 2.0

Third Party Library 第三方庫

All these libraries are statically linked by default.

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.2.0.tar.gz (3.4 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.2.0-cp312-cp312-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12

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

Uploaded CPython 3.12macOS 11.0+ ARM64

opencc-1.2.0-cp311-cp311-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11

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

Uploaded CPython 3.11macOS 11.0+ ARM64

opencc-1.2.0-cp310-cp310-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10

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

Uploaded CPython 3.10macOS 11.0+ ARM64

opencc-1.2.0-cp39-cp39-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.9Windows x86-64

opencc-1.2.0-cp39-cp39-manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9

opencc-1.2.0-cp39-cp39-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

opencc-1.2.0-cp38-cp38-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.8Windows x86-64

opencc-1.2.0-cp38-cp38-manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.8

opencc-1.2.0-cp38-cp38-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: opencc-1.2.0.tar.gz
  • Upload date:
  • Size: 3.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for opencc-1.2.0.tar.gz
Algorithm Hash digest
SHA256 2bb913c7ed388466b26d38af4c8c4bb419ddb503235d070f0ee1b24998ef8bca
MD5 ea9caa4772e4a5b8668a82028e743597
BLAKE2b-256 fa9292f4519221b833801be1d037cde747f04c4e29e33bd7574b36b898d9e2bf

See more details on using hashes here.

File details

Details for the file opencc-1.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: opencc-1.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for opencc-1.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 76cf42a9666ac5402478f7fad2f603d253096aa5c41199b173e08d49a9af8046
MD5 bd14dfac04d42db882915d8150e8bf78
BLAKE2b-256 d0f60900195298326bd038469f3db571afd73b893a30fe92648f6418162a4cb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencc-1.2.0-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1f105a05fc76c29a1090cb613996aef26b60525e745e8471dc4485dfe17f2e08
MD5 4049edd58b21fc961e97f84788afcdc9
BLAKE2b-256 f3f8fc8c5f25243a886dcf15329060e3596e4ab967ee2e277920e4feb6067211

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencc-1.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c9851a7b7d50e4c5d52c71972cedbb618542a342ed57ce396be8988bfefdf040
MD5 2d711d772214e7c4438d90b93e78442c
BLAKE2b-256 f289c3654977ae86211342356c5f455a26d93dd47222c2444e945aab6a4f91cc

See more details on using hashes here.

File details

Details for the file opencc-1.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: opencc-1.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for opencc-1.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f6b631419fae0a1d590eb605699c0507d7f3e43b4e601555d12bf59043dc34d1
MD5 731a58d24b6d11dac6d2a6aeaed1ffee
BLAKE2b-256 21d2d25fce5e58204fbe7722684b49cfd896bd01e11f1a31cec417c19b39bea5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencc-1.2.0-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6ab92dc34be23a710e98162347287d152bb8ac2ed62fc646dc70a1ab44e2540f
MD5 9b35093bf4cf124371dbd87c88d53aab
BLAKE2b-256 2fe9fa3308bae32fd4f2c5539703a96500aee8006cfcfa975a77106c0fd1e553

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencc-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 696fc0fd0fe4ee1d678c4783af07733425299bc1ed70e55595275d15087006dd
MD5 dc2cd0b4ef9b960218f6f2e06b446cb4
BLAKE2b-256 abf99c70995ba3b9839b5754bd3fe4b7bad46b252a343601e17bcac21d86ce6a

See more details on using hashes here.

File details

Details for the file opencc-1.2.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: opencc-1.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for opencc-1.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 127437a9173bea7be78bb722a2705238ec7a53cf576a7e20312407abe0a28a45
MD5 8af86ccfd26ee677f7f716d4ba90d220
BLAKE2b-256 dd631d1a91d1b913e600c8d65c302ba445a22bcbba9f38f23addbc5a77ca6e66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencc-1.2.0-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd62b27d50d057194fea66e066b558362d0c543739a32a4d2ccef11a3b7c2a07
MD5 225aa901ec1f9de08cd5622853710495
BLAKE2b-256 03ab7f73fc8a7d62091d7b01fb2b21708dfd38df429b058b9767abddce7d0b87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opencc-1.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 909a7902d09333509a4bf31f3bb5dd21c5cbdde966601a3ae69a3f38c1d8a6c0
MD5 0c17641ff1bad68a345f6896a4b6f9fb
BLAKE2b-256 c7eecbb613d82921d214fb789b4b0a539d8be6b5392e1b6591cf566dcd13be92

See more details on using hashes here.

File details

Details for the file opencc-1.2.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: opencc-1.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for opencc-1.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 fd4c89a82d21cd579e8de1af5883dc4e7b1333278f38723990f59e5a3f96d5d5
MD5 03525daaf54420e4306fe8e9556713c4
BLAKE2b-256 f864408aad97be72d17c045259dba3d152acb74c0e1fe08a4be300e7dc3e7c3b

See more details on using hashes here.

File details

Details for the file opencc-1.2.0-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencc-1.2.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 400d18c3c989fff68701be9d059bf133a6338d4f602991d3fdf4eb1a7939d518
MD5 9ca8c72ac8de962dbef10715c0b69bfe
BLAKE2b-256 8b1dd612dca998868bfe9874bfd16bd3f2126c4e5a6b13e101c88bc4773459aa

See more details on using hashes here.

File details

Details for the file opencc-1.2.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencc-1.2.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 66b02f91a53532267328a88d7013309ac7504c13bf957385c84107fe4d028317
MD5 6cab42054279392e8a48a1cd34d3f2fe
BLAKE2b-256 ac984577b64b2af5856200021f0883f28a003dd9421c4426dddf823c798ebc89

See more details on using hashes here.

File details

Details for the file opencc-1.2.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: opencc-1.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for opencc-1.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 d803ba9934af2eb0570f91f6115b691cab121310bd0cac4de9ee86dc572f1067
MD5 385df6b024a5710f8eb65edff6636102
BLAKE2b-256 76ae9d4a0309f6741017c10637095c8dd4d4ac7de7db67721f386051bca0d8aa

See more details on using hashes here.

File details

Details for the file opencc-1.2.0-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opencc-1.2.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 57860f546b9f8ad4ddc6fa5d53e09f933c7a238a0f13c7f94b4505592edc3b31
MD5 37ac3de06d4acec650a534e20d2e2b66
BLAKE2b-256 72f64563ad22f1d8433b6399f7c573c9151786f4c67e08dabe13ed89fb2dc7d7

See more details on using hashes here.

File details

Details for the file opencc-1.2.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opencc-1.2.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e94d080069f0e3e387fcd12c6b07cea2f50201d8af69cfd6de62b20e34bf6875
MD5 675db9487096233d1d68a9d7bd12d491
BLAKE2b-256 4133529ed3632e46efe7da09efe7ae19acbfe0f5b951fc0cf00f92d3d28fa894

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