Translate comma-separated terms (#554, #535)

This commit is contained in:
Igor Chubin 2021-01-02 22:48:17 +01:00
parent 0b8ead03e6
commit 492f4f5e50

View file

@ -126,11 +126,17 @@ def _save_content_and_headers(path, query, content, headers):
def translate(text, lang):
"""
Translate `text` into `lang`
Translate `text` into `lang`.
If `text` is comma-separated, translate each term independently.
If no translation found, leave it untouched.
"""
if "," in text:
terms = text.split(",")
translated_terms = [translate(term.strip(), lang) for term in terms]
return ", ".join(translated_terms)
translated = TRANSLATIONS.get(lang, {}).get(text.lower(), text)
if text == translated:
print("%s: %s" % (lang, text))
return translated
def cyr(to_translate):