|
22 | 22 | from googletrans import Translator |
23 | 23 | GoogleTranslate = Translator(service_urls=["translate.google.us"]) |
24 | 24 |
|
| 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 | + |
25 | 58 | # Google allows up to 500K chars translation/month, so using a key likely would be free anyway |
26 | 59 |
|
27 | 60 | # Got blocked trying to translated unicode-full.yaml (~8,100 text strings). |
|
0 commit comments