deep-translator
deep-translator copied to clipboard
Arabic Translation returnning an error
import re
def translate_name(name):
def has_arabic(text):
# Regular expression pattern for Arabic characters
arabic_pattern = re.compile(r"[\u0600-\u06FF]")
return bool(arabic_pattern.search(text))
from deep_translator import GoogleTranslator
names = name.split(" ")
res = []
for name in names:
if has_arabic(name):
s = "اسمي هو محمد " + name # اسمي مش محمد
translated = GoogleTranslator(source="auto", target="english").translate(
text=s
)
translated_array = translated.split(" ")
if len(translated_array) <= 3:
return translated_array[-1]
res.extend(translated_array[4:])
else:
res.append(name)
return " ".join(res)
print(translate_name("احمد"))
The following code worked previously now it's returning this Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
I believe this error is infamous with google stuff, maybe it's down