[Golang] Converter for Traditional and Simplified Chinese


gojianfan is a converter implemented in Golang for conversion of Traditional and Simplified Chinese. It is a very primitive, and based on python-jianfan. If you need a advanced converter, please visit OpenCC (GitHub repo) [2].

Implementation of gojianfan

The Chinese writing language consists of large number of characters. Normally speaking, one character in Traditional Chinese can be mapped to one character in Simplified Chinese, and vice versa (although this statement may not be true in some cases). The most basic form of converter is to construct mappings between characters in Traditional and Simplified Chinese, and then do the conversion character by character according to the mapping. This is how gojianfan is implemented. The idea is simple, and the most difficult part is to find the mapping of character sets. I found the mapping in the source code of python-jianfan, and write the converter in Go according to the mapping in python-jianfan. The Go implementation is only a few lines of code and easy to understand. Please visit gojianfan if you want to know more details.

Usgae

First install the package by:

$ go get -u github.com/siongui/gojianfan

Example:

package main

import (
      "fmt"
      "github.com/siongui/gojianfan"
)

func main() {
      // Traditional Chinese to Simplified Chinese
      fmt.Println(gojianfan.T2S("橋頭"))

      // Simplified Chinese to Traditional Chinese
      fmt.Println(gojianfan.S2T("桥头"))
}

Tested on: Ubuntu Linux 16.10, Go 1.8.


References:

[1]GitHub - siongui/gojianfan: Traditional and Simplified Chinese Conversion in Go
[2][Golang] Conversion of Traditional and Simplified Chinese
[3][JavaScript] Conversion of Traditional and Simplified Chinese
[4][Python] Conversion of Traditional and Simplified Chinese