use separate module for translator

This commit is contained in:
Manuel Schmid
2023-11-25 23:21:09 +01:00
parent 65af7d3764
commit eeb1013638
2 changed files with 17 additions and 15 deletions
+15
View File
@@ -0,0 +1,15 @@
import translators
from functools import lru_cache
@lru_cache(maxsize=32, typed=False)
def translate2en(text, element):
if not text:
return text
try:
result = translators.translate_text(text,to_language='en')
print(f'Translated {element}: {result}')
return result
except Exception as e:
print(f'Error during translation of {element}: {e}')
return text