Skip to content

Commit 846533a

Browse files
committed
Added some comments and sample code to switch from using googletrans to deepl which might do a better job with the translations.
1 parent 7510b3d commit 846533a

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

PythonScripts/translate-unicode.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,39 @@
2222
from googletrans import Translator
2323
GoogleTranslate = Translator(service_urls=["translate.google.us"])
2424

25+
''' In some manual testing, DeepL seems to do better than Google Translate
26+
deepl requires an API key.
27+
There is a free tier, but it won't do a full translation in the monthly free tier (50K chars/month)
28+
There are ~76k chars to translate, with ~62k of them being in unicode-full.yaml
29+
The lowest paid tier gives 300k chars/month for $10.50, so four translations/month if no problems.
30+
Maybe run unicode-full.yaml through Google and the rest through DeepL?
31+
Below is sample DeepL code -- commented out for now.
32+
'''
33+
# import deepl
34+
# import os
35+
36+
# # 1. Set up the Translator
37+
# # It's best practice to use an environment variable for your API key.
38+
# # You can set this variable: DEEPL_AUTH_KEY="YOUR_API_KEY"
39+
# auth_key = os.getenv("DEEPL_AUTH_KEY", "YOUR_API_KEY")
40+
# translator = deepl.Translator(auth_key)
41+
42+
# # 2. Define the text and target language
43+
# text_to_translate = "Hello, world!"
44+
# target_language = "FR" # French
45+
46+
# # 3. Call the translation method
47+
# # Omitting 'source_lang' allows DeepL to auto-detect the language.
48+
# result = translator.translate_text(
49+
# text_to_translate,
50+
# target_lang=target_language
51+
# )
52+
53+
# # 4. Print the result
54+
# print(f"Original Text: {text_to_translate}")
55+
# print(f"Translated Text: {result.text}")
56+
# print(f"Source Language Detected: {result.detected_source_lang}")
57+
2558
# Google allows up to 500K chars translation/month, so using a key likely would be free anyway
2659

2760
# Got blocked trying to translated unicode-full.yaml (~8,100 text strings).

0 commit comments

Comments
 (0)