File size: 971 Bytes
7a05cd7 c754d32 3e848bc 283a7d3 d03a2fc c754d32 d03a2fc 3e848bc d03a2fc 283a7d3 d03a2fc 3e848bc c754d32 283a7d3 cb15d3a c754d32 283a7d3 c754d32 |
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 |
from deep_translator import GoogleTranslator, LingueeTranslator, PonsTranslator
# examples using google translate
english_text = "happy coding"
chinese_text = "這很好"
translator = GoogleTranslator(source="auto", target="german")
result1 = translator.translate(text=english_text)
result2 = translator.translate(text=chinese_text)
print(f"original english text: {english_text} | translated text: {result1}")
print(f"original chinese text: {chinese_text} | translated text: {result2}")
# file translation
result_file = translator.translate_file("./test.txt")
print("file translation: ", result_file)
# examples using linguee:
text = "cute"
translated = LingueeTranslator(source="english", target="german").translate(
word=text
)
print("Using Linguee ==> the translated text: ", translated)
# examples using pons:
text = "good"
translated = PonsTranslator(source="en", target="ar").translate(word=text)
print("using Pons ==> the translated text: ", translated)
|