forked from Animenosekai/translate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Google Translate & DeepL Translate & Improved CLI mode & New
tests
- Loading branch information
1 parent
a87bd79
commit faf4b27
Showing
17 changed files
with
598 additions
and
858 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from translatepy.translators.google import GoogleTranslateV1, GoogleTranslateV2 | ||
from translatepy.translators.bing import BingTranslate | ||
from translatepy.translators.yandex import YandexTranslate | ||
from translatepy.translators.reverso import ReversoTranslate | ||
from translatepy.translators.deepl import DeeplTranslate | ||
from translatepy import Translator | ||
|
||
|
||
class TestAllTranslators: | ||
def setup(self): | ||
self.services_list = [ | ||
Translator(), | ||
GoogleTranslateV1(), | ||
GoogleTranslateV2(), | ||
BingTranslate(), | ||
ReversoTranslate(), | ||
YandexTranslate(), | ||
DeeplTranslate(), | ||
] | ||
|
||
def test_service_translate(self): | ||
translation_args_list = [["What cool weather today!", "fr"], | ||
["Hello", "Japanese", "en"], | ||
["Hello, how are you?", "ja"]] | ||
|
||
for service in self.services_list: | ||
for args in translation_args_list: | ||
result = service.translate(*args) | ||
assert result | ||
|
||
def test_service_transliterate(self): | ||
transliteration_args_list = [["What cool weather today!", "ar"], | ||
["Hello", "Japanese", "en"], | ||
["Hello, how are you?", "ja"]] | ||
|
||
for service in self.services_list: | ||
for args in transliteration_args_list: | ||
result = service.transliterate(*args) | ||
assert result | ||
|
||
def test_service_spellcheck(self): | ||
spellcheck_args_list = [["What cool weater todai!"], ["Helo"], | ||
["Helo, how are tou?"]] | ||
|
||
for service in self.services_list: | ||
for args in spellcheck_args_list: | ||
result = service.spellcheck(*args) | ||
assert result |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
import argparse | ||
from translatepy import Translator | ||
|
||
dl = Translator() | ||
|
||
# Create the parser | ||
my_parser = argparse.ArgumentParser(prog='translatepy-cli', description='Translate, transliterate, get the language of texts in no time with the help of multiple APIs!') | ||
def main(): | ||
dl = Translator() | ||
|
||
subparser = my_parser.add_subparsers(help='Actions', dest="action", required=True) | ||
parser_translate = subparser.add_parser('translate', help='Translates the given text to the given language') | ||
parser_translate.add_argument('--text', '-t', action='store', type=str, required=True, help='text to translate') | ||
parser_translate.add_argument('--dest-lang', '-d', action='store', type=str, required=True, help='destination language') | ||
parser_translate.add_argument('--source-lang', '-s', action='store', default='auto', type=str, help='source language') | ||
# Create the parser | ||
my_parser = argparse.ArgumentParser(prog='translatepy-cli', description='Translate, transliterate, get the language of texts in no time with the help of multiple APIs!') | ||
|
||
args = my_parser.parse_args() | ||
subparser = my_parser.add_subparsers(help='Actions', dest="action", required=True) | ||
parser_translate = subparser.add_parser('translate', help='Translates the given text to the given language') | ||
parser_translate.add_argument('--text', '-t', action='store', type=str, required=True, help='text to translate') | ||
parser_translate.add_argument('--dest-lang', '-d', action='store', type=str, required=True, help='destination language') | ||
parser_translate.add_argument('--source-lang', '-s', action='store', default='auto', type=str, help='source language') | ||
|
||
if args.action == 'translate': | ||
result = dl.translate(args.text, args.dest_lang, args.source_lang) | ||
print(result) | ||
parser_translate = subparser.add_parser('shell', help='Translates the given text in interactive shell mode') | ||
|
||
args = my_parser.parse_args() | ||
|
||
if args.action == 'translate': | ||
result = dl.translate(args.text, args.dest_lang, args.source_lang) | ||
print(result) | ||
|
||
if args.action == 'shell': | ||
while True: | ||
input_text = input(">>> ") | ||
|
||
result = dl.translate(input_text, "en") | ||
print(result) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
# TODO | ||
|
||
""" | ||
from .bing import BingTranslator | ||
from .deepl import DeepLTranslator | ||
from .google import GoogleTranslator, GoogleV2Translator | ||
from .reverso import ReversoTranslator | ||
from .translator import Translator | ||
from .yandex import YandexTranslator | ||
""" | ||
from translatepy.translators.google import GoogleTranslateV1, GoogleTranslateV2 | ||
from translatepy.translators.bing import BingTranslate | ||
from translatepy.translators.yandex import YandexTranslate | ||
from translatepy.translators.reverso import ReversoTranslate | ||
from translatepy.translators.deepl import DeeplTranslate |
Oops, something went wrong.