OpenCC made with Python

0.1.7 · active · verified Sat Apr 11

OpenCC-python-reimplemented is a pure Python implementation of the Open Chinese Convert (OpenCC) library. It facilitates conversions between Traditional and Simplified Chinese, supporting character-level and phrase-level conversion, as well as handling character variants and regional idioms among Mainland China, Taiwan, and Hong Kong. The current version is 0.1.7, released in February 2023, indicating an infrequent release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the OpenCC converter with a specific conversion configuration (e.g., Simplified to Traditional Chinese) and perform text conversion. It also shows an example of Traditional to Simplified Chinese conversion.

from opencc import OpenCC

cc = OpenCC('s2t') # Initialize converter: Simplified Chinese to Traditional Chinese
to_convert = '你好,世界!开放中文转换。'
converted_text = cc.convert(to_convert)
print(f"Original: {to_convert}")
print(f"Converted (s2t): {converted_text}")

# Example with another conversion mode (Traditional Chinese to Simplified Chinese)
cc_t2s = OpenCC('t2s')
to_convert_t = '你好,世界!開放中文轉換。'
converted_text_s = cc_t2s.convert(to_convert_t)
print(f"Original: {to_convert_t}")
print(f"Converted (t2s): {converted_text_s}")

view raw JSON →