Hello, everyone , I'm a panda
First introduced opencc Medium Python Implementation library , It has simple installation , The translation is accurate , Easy to use and other advantages . We are fully qualified for our daily needs .
First, in the terminal Install in opencc-python.
pip install opencc-python
There are four built-in opencc Translation configuration :
•t2s - Traditional to simplified (Traditional Chinese to Simplified Chinese)
•s2t - From simplified Chinese to traditional Chinese (Simplified Chinese to Traditional Chinese)
•mix2t - Mixed to traditional (Mixed to Traditional Chinese)
•mix2s - Mixed to simplified (Mixed to Simplified Chinese)
import opencc Python plug-in unit / material /. Source code Q Group :660193417 ####
cc = opencc.OpenCC('t2s')
print(cc.convert(u'Open Chinese Convert(OpenCC) Open Chinese conversion , It is a project dedicated to the conversion of simplified and complex Chinese , Provide high-quality thesaurus and function library (libopencc).'))
The output is as follows :
utilize Python Some people have also developed commands to realize the conversion between simplified and traditional Chinese characters , And release to the github On , Address :https://github.com/skydark/nstools/tree/master/zhtools. Download... From this project zh_wiki.py and langconv.py Two documents , Put it in python Just under the code directory .
from langconv import Converter
def convert(text, flag=0): #text For the text to be converted ,flag=0 Represents simplification and complexity ,flag=1 Represents complexity and simplification
rule = 'zh-hans' if flag else 'zh-hant'
return Converter(rule).convert(text)
text1 = ' Quietly is the farewell music ; Summer insects are silent for me , Silence is Cambridge tonight 'print(convert(text1))
text2 = ' Silence is the farewell Sheng Xiao ; Summer insects are silent for me , Silence is Cambridge tonight 'print(convert(text2, 1))
The converted result is :
This method has the advantage of light weight , Easy to use , concise , But the translation may not be accurate .
zhconv The library is used directly pip install , The installation command is :
pip install zhconv
zhconv Support the conversion of the following regional words :
Method 1: Direct import zhconv1
import zhconv
text = ' This go to years , Should be a good time . There are thousands of styles , More with who said ?'
text1 = zhconv.convert(text, 'zh-hant')
text2 = zhconv.convert(text, 'zh-tw')
text3 = zhconv.convert(text, 'zh-hk')
print(' Convert to traditional Chinese :', text1)
print(' Convert to Taiwanese orthodox :', text2)
print(' Convert to Hong Kong traditional :', text3)
The result of the conversion is :
from zhconv import convert
text = ' This go to years , Should be a good time . There are thousands of styles , More with who said ?'
text1 = convert(text, 'zh-hant')
print(' Convert to traditional Chinese :', text1)
The result of the conversion is :
Leverage extension Libraries python-docx, Can be Word Convert the Chinese in the document , Convert simplified to traditional :
pip install python-docx
Here we use zhconv Library to put word file 《 hurriedly 》 Convert to 《 hurriedly 》 Traditional Chinese version :
from zhconv import convert
from docx import Document
word = Document('《 hurriedly 》.docx')
for t in word.paragraphs:
t.text = convert(t.text, 'zh-hant')for i in word.tables:
for p in i.rows:
for h in p.cells:
h.text = convert(h.text, 'zh-hant')
word.save('《 hurriedly 》 Traditional Chinese version .docx')
Before conversion :
After the transformation :
In this way, we will achieve 《 hurriedly 》 This document is converted to traditional Chinese version .
This is about Python This is the end of the article to realize the transformation between simple and traditional Chinese , More about Python Please continue to pay attention to the following related articles for the conversion between simplified and traditional Chinese and other contents !
As McKinsey said , Data has pe
Everything is a process from q