undefined

以下紀錄 Python 中簡轉繁、繁轉簡功能的使用:

Step 1:

請先抓取下述的 python file

https://github.com/skydark/nstools 中的
 

https://github.com/skydark/nstools/blob/master/zhtools/zh_wiki.py

https://github.com/skydark/nstools/blob/master/zhtools/langconv.py

 

Step 2: 將這兩個檔案與實作專案的檔案放在同一個目錄下,使用下述 sample code 即可進行轉換。

簡轉繁:

#coding: utf-8
from langconv import Converter
sentence = "测试"
line = Converter('zh-hant').convert(sentence.decode('utf-8'))
line = line.encode('utf-8')
print ("簡轉繁: " + sentence)

Console:

簡轉繁: 測試

繁轉簡:

#coding: utf-8
from langconv import Converter
sentence = "測試"
line = Converter('zh-hans').convert(sentence.decode('utf-8'))
line = line.encode('utf-8')
print ("繁轉簡: " + sentence)

Console:

繁轉簡: 测试

 

 

[Reference]

1. https://blog.csdn.net/tab_space/article/details/50823073

2. http://fecbob.pixnet.net/blog/post/43573258-%5Bpython%5D-%E7%B9%81%E9%AB%94%E5%92%8C%E7%B0%A1%E9%AB%94%E4%B9%8B%E9%96%93%E7%9A%84%E8%BD%89%E6%8F%9B

3. https://gist.github.com/zfz/2d7d9c9c5f74b19330df

4. https://github.com/skydark/nstools

 

 

arrow
arrow
    全站熱搜

    葛瑞斯肯 發表在 痞客邦 留言(2) 人氣()