-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcltran.py
36 lines (28 loc) · 1.09 KB
/
cltran.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import sys
import subprocess
import lib.config as cg
from lib.run import run
def tran(text):
relist = cg.get_relist()
# relist = [('^ {0,6}\\b(.*):', 1), (' .*? \\b(.*)', 1), (' .*?^[A-Z] \\b(.*)', 1), ('^ {3,30}\\b(.*)', 1),
# ('^ ?\\b(.*)', 1)]
if cg.show_original_text:
print(text)
result = run(text, relist)
print(result)
if __name__ == '__main__':
if len(sys.argv) > 1:
if sys.argv[1] == '-h' or sys.argv[1] == '-help':
print("usage: cltran <cmd>\t", end='')
print("cmd为'-h'或'-hlep'显示帮助信息,为其它命令则执行命令并翻译, \n\t\t\t也可以直接通过“ | ”连接符进行管道翻译")
else:
cmd = subprocess.run(sys.argv[1:], shell=True, stdout=subprocess.PIPE, encoding="utf-8",
timeout=cg.timeout, universal_newlines=True)
tran(cmd.stdout)
else:
if not sys.stdin.isatty():
content = sys.stdin.read()
sys.stdin.close()
tran(content)