Hanzi Converter

repository·master·Indexed 41 days ago

https://github.com/berniey/hanziconv

A tool and Python library for converting between Simplified and Traditional Chinese characters. It provides a programmatic API via the hanziconv module and a command-line interface called hanzi-convert, compatible with Python 2 and 3.

Tokens
655
Snippets
6
Records
6
Agent score
2%

What's inside hanziconv

  1. Run tests for hanziconv

    master

    The project uses pytest for testing. To run tests, install pytest and execute the test command from the source directory.

    $ [sudo] pip install pytest
    $ git clone https://github.com/berniey/hanziconv
    $ cd hanziconv
    $ python setup.py test
  2. Use the HanziConv Python API

    master

    Import HanziConv from the hanziconv module to perform conversions programmatically within your Python code.

    from hanziconv import HanziConv
    
    # Convert to Simplified
    print(HanziConv.toSimplified('繁簡轉換器'))  # Output: 繁简转换器
    
    # Convert to Traditional
    print(HanziConv.toTraditional('繁简转换器'))  # Output: 繁簡轉換器
    
    # Check if two strings are equivalent in both forms
    print(HanziConv.same('繁簡轉換器', '繁简转换器'))  # Output: True
  3. Reference: hanzi-convert CLI arguments

    master

    The following arguments are available for the hanzi-convert command line tool:

    positional arguments:
      infile                filename | "-", corresponds to stdin
    
    optional arguments:
      -h, --help            show this help message and exit
      -o OUTFILE, --output OUTFILE
                            filename to save output, stdout if omitted
      -s, --simplified      convert to simplified characters
      -v, --version         show program's version number and exit
  4. Use the hanzi-convert CLI tool

    master

    The hanzi-convert command line tool converts between Simplified and Traditional Chinese characters. By default, it converts to Traditional characters unless the -s flag is provided.

    # Conversion from stdin
    $ ./hanzi-convert -