Skip to main content

A library to convert variant Chinese characters to standard simplified or traditional characters.

Project description

Image

Chinese Character Variant Converter,

an open-source library for converting Chinese character variants to standard simplified or traditional characters.

* About the project's name and logo: "CHAR" comes from "Chinese character variant" and also refers to a type of beautiful fish with a gradient of red color (Arctic Char).

Online Demo

Char Converter Demo

News

2024-11-15: npm package for JavaScript has been released.

Python

Install

pip install char-converter

Update

Important Note: We have been checking and updating the data from time to time. Please run the following command to ensure the package is the latest version before using it to handle important mateirals every time.

pip install char-converter -U

Usage

Convert text

  1. Mode: one2one
from char_converter import CharConverter

text = '苟馀情其訫姱㠯练要兮,镸顑頷亦何伤。'

converter = CharConverter('v2t')
converted_text = converter.convert(text)
# 苟餘情其信姱以練要兮,長顑頷亦何傷。

converter = CharConverter('v2s')
converted_text = converter.convert(text)
# 苟余情其信姱以练要兮,长顑颔亦何伤。
  1. Mode: one2many
from char_converter import CharConverter

text = '鈡𩄇毓秀'

converter = CharConverter('v2t')
converter.set_mode('one2many')
converted_text = converter.convert(text)
# 【鍾|鐘】靈毓秀

Convert file

from char_converter import CharConverter

converter = CharConverter('v2s')
converter.convert_file(input_file, output_file)

HTML

<script src="https://unpkg.com/char_converter@latest/dist/bundle.js"></script>
<script>
  const CharConverterClass = CharConverter.default;

  const converter = new CharConverterClass('v2t', 'offline');
  converter.setMode('one2many');

  async function testConversion() {
    const result = await converter.convert('鈡𩄇毓秀');
    console.log(result);
  }

  testConversion();
</script>

JavaScript

Install

npm install char_converter

Update

Important Note: We have been checking and updating the data from time to time. When initializing the converter, two options ("online" and "offline") are both available. If choosing "online", the data will be retrieved directly from the updated online source. If choosing "offline", please run the following command to ensure the package is the latest version regularly to check if the data is up-to-date.

npm install char_converter@latest

Usage

Convert text

  1. Mode: one2one
const CharConverter = require('char_converter');

const text = '苟馀情其訫姱㠯练要兮,镸顑頷亦何伤。';

const converter = new CharConverter('v2t', source = 'online'); // Variant to Traditional
converter.setMode('one2one');
const convertedText = converter.convert(text);
console.log(convertedText); // 苟餘情其信姱以練要兮,長顑頷亦何傷。

const converter = new CharConverter('v2s', source = 'online'); // Variant to Simplified
converter.setMode('one2one');
const convertedText = converter.convert(text);
console.log(convertedText); // 苟余情其信姱以练要兮,长顑颔亦何伤。
  1. Mode: one2many
const CharConverter = require('char_converter');

const text = '鈡𩄇毓秀'

const converter = new CharConverter('v2t', source = 'online'); // Variant to Traditional
converter.setMode('one2many');
const convertedText = converter.convert(text);
console.log(convertedText); // 【鍾|鐘】靈毓秀

Data source

CBDB Project

OpenCC image

Dictionary of Variant Chinese Characters

General Standard Chinese Characters Table

Data filtering

Image

Contributors

Yuqi Chen (data collection and programming)

Hongsu Wang (project manager)

Yiyi Wang (proofreading)

Fengyi Ji (data collection)

Kaini Xiong (proofreading)

License

License: CC BY-SA 4.0

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

char_converter-0.50.tar.gz (80.6 kB view details)

Uploaded Source

Built Distribution

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

char_converter-0.50-py3-none-any.whl (77.2 kB view details)

Uploaded Python 3

File details

Details for the file char_converter-0.50.tar.gz.

File metadata

  • Download URL: char_converter-0.50.tar.gz
  • Upload date:
  • Size: 80.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for char_converter-0.50.tar.gz
Algorithm Hash digest
SHA256 da75681beb4a782d8eaf850bac9fe4dc5ebfd34bda32e38fca57f330dd4a1414
MD5 5930751d669c6139d06339e9cc0b32a0
BLAKE2b-256 616038af2ed26879fd18dca445fc683e9d0bc8992e643304af5372ff5c519ca0

See more details on using hashes here.

File details

Details for the file char_converter-0.50-py3-none-any.whl.

File metadata

  • Download URL: char_converter-0.50-py3-none-any.whl
  • Upload date:
  • Size: 77.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for char_converter-0.50-py3-none-any.whl
Algorithm Hash digest
SHA256 309fc262528c2f1d56cdfa9bb44f10891d3729ab24fe8f8788825e7fbe7786cc
MD5 58dd89402e691b68e1f8177181ea357f
BLAKE2b-256 be4e881f12f3ca50e0b9275b4cba042195496eb62e7b0d705d322af20f6520c8

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