wmt-2020-pl-en/translate
2015-06-05 23:43:05 +09:00

28 lines
950 B
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
from googletrans import translator
def main():
parser = argparse.ArgumentParser(
description='Python Google Translator as a command-line tool')
parser.add_argument('text', help='The text you want to translate.')
parser.add_argument('-d', '--dest', default='en',
help='The destination language you want to translate. (Default: en)')
parser.add_argument('-s', '--src', default='auto',
help='The source language you want to translate. (Default: auto)')
args = parser.parse_args()
result = translator.translate(args.text, dest=args.dest, src=args.src)
result = """
[{src}] {original}
->
[{dest}] {text}
[pron.] {pronunciation}
""".strip().format(src=result.src, dest=result.dest, original=result.origin,
text=result.text, pronunciation=result.pronunciation)
print(result)
if __name__ == '__main__':
main()