-
Notifications
You must be signed in to change notification settings - Fork 9
/
trans
executable file
·35 lines (31 loc) · 1.96 KB
/
trans
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import sys
import re
from mkTranslation import utils
from mkTranslation.translator import mkTranslator
def main():
parser = argparse.ArgumentParser(description='Command line tools translated using Google、youdao and i18ns.com')
parser.add_argument('text',help='translate text directly at the terminal')
parser.add_argument('-d','--dest',action='store',dest='dest_language',default='en',help='The destination language you want to translate. (Default: "en",繁体:"t",简体:"s")')
parser.add_argument('-c','--channel',action='store',dest='channel',default='google',help='By default, google translation can be used to specify other translation channels.([-c "google"] or [-c "youdao"])')
parser.add_argument('-s','--sourcelanguage',action='store',dest='sourcelanguage',help='Set the original file language, first use "i18ns.com" translation')
parser.add_argument('-a', '--detect', action='store_true', default=False,help='')
args = parser.parse_args()
if(args.dest_language):
if(args.dest_language == 's' or args.dest_language == 't'):
args.dest_language = 'zh-han' + args.dest_language
elif(re.search(r'zh-[HK|MO|SG|TW]',args.dest_language)):
args.dest_language = 'zh-hant'
elif(args.dest_language == 'zh-CN'):
args.dest_language = 'zh-hans'
utils.printf('Target language '+args.dest_language)
if args.detect:
mkTranslator().translate_text(text=args.text, destination=args.dest_language,sourcelanguage=args.sourcelanguage,channel=args.channel)
elif(args.text):
mkTranslator().translate_text(text=args.text, destination=args.dest_language,sourcelanguage=args.sourcelanguage,channel=args.channel)
else:
utils.printf('-p:path of the document being translated -d:target language (Default: "en",繁体:"t",简体:"s") -c:translation channel:[-c "google"] or [-c "youdao"] ')
if __name__ == '__main__':
main()