Console/terminal demo of Chinese Traditional and Simplified conversion with OpenCC, supporting Windows 11 and Ubuntu Linux 24.04. Ten conversion modes are available, covering Simplified and Traditional as well as the Taiwan and Hong Kong variants, and some modes also convert the regional idioms. You can convert text given on the command line or a whole text file, printing the result or writing it to an output file. The conversion is dictionary-based, so it runs fully offline in pure Python with no GPU.

 

[Conversion Modes]

  • hk2s: Traditional (Hong Kong) to Simplified.
  • s2hk: Simplified to Traditional (Hong Kong).
  • s2t: Simplified to Traditional.
  • s2tw: Simplified to Traditional (Taiwan).
  • s2twp: Simplified to Traditional (Taiwan), with idiom conversion.
  • t2hk: Traditional to Traditional (Hong Kong).
  • t2s: Traditional to Simplified.
  • t2tw: Traditional to Traditional (Taiwan).
  • tw2s: Traditional (Taiwan) to Simplified.
  • tw2sp: Traditional (Taiwan) to Simplified, with idiom conversion. This is the default.
  • The modes ending in p also swap the regional vocabulary, not just the characters; the modes without p convert the characters only.

[Folder Structure]

  • CLAUDE.md / AGENT.md: program specification (identical content).
  • CHANGELOG.md: change log.
  • copyright.txt: copyright notice.
  • data/examples/traditional_tw.txt: the notebook's example sentence.
  • tool/tools.py: shared helpers.
  • src/: the demo, the launcher scripts and this document.
  • venv/: Python virtual environment, created by step 1.

There is no model/ folder, because the conversion is dictionary-based and needs no model file.

 

[Prerequisites]

  • Operating system: Windows 11 or Ubuntu Linux 24.04.
  • Python 3 and pip.
  • The dependency (opencc-python-reimplemented) is listed in src/requirements.txt and installed by step 1.
  • No GPU required.

[Instructions]

Step 1: create the virtual environment

Delete the old venv/, create a fresh one and install src/requirements.txt (opencc-python-reimplemented). Aborts loudly if pip fails.

 

Windows 11: src\01_venv_create.bat

Ubuntu 24.04: bash src/01_venv_create.sh

 

Step 2: activate the virtual environment

Activate the venv you just created. On Linux, source it so the environment variables apply to the current shell.

 

Windows 11: src\02_venv_activate.bat

Ubuntu 24.04: source src/02_venv_activate.sh

 

Step 3: convert Chinese text

Convert the bundled example sentence with the default tw2sp mode. Extra arguments are forwarded to the Python script.

 

Windows 11: src\03_opencc.bat

Ubuntu 24.04: bash src/03_opencc.sh

Another mode and your own text, or a whole file:

bash src/03_opencc.sh --mode s2twp --text "the text to convert"

bash src/03_opencc.sh --file input.txt --output converted.txt

 

Step 4: clear the virtual environment (optional)

Delete the venv/ folder to free disk space when you no longer need it.

 

Windows 11: src\99_venv_clear.bat

Ubuntu 24.04: bash src/99_venv_clear.sh

 

[Python Entry Point]

  • src/opencc_convert.py: [--mode tw2sp] [--text T] [--file data/examples/traditional_tw.txt] [--output OUT].
  • --mode: the conversion mode, tw2sp by default.
  • --text: the text to convert, given directly on the command line.
  • --file: convert a UTF-8 text file instead, default data/examples/traditional_tw.txt.
  • --output: write the result to this file; without it the result is printed to the console.

[References]

 

This SDK is built in AppForAI - AI Dev Tools.

 

Purchase license separately:  USD 600, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.