close
以下紀錄 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
3. https://gist.github.com/zfz/2d7d9c9c5f74b19330df
4. https://github.com/skydark/nstools
全站熱搜
留言列表