Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Translation helper function
  • Loading branch information
kthoden committed Jun 12, 2019
1 parent 292bee7 commit 61221ee
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions utils/libeoaconvert.py
Expand Up @@ -425,3 +425,22 @@ def get_appinfo(ident, version, xmlid, text, date):

return fix_tei_info
# def get_appinfo ends here

def translate(term, publang, translation_file):
"""Translate a term"""

translation_xml = etree.parse( str( translation_file ) )
try:
term_to_translate = translation_xml.find(f"//entry[@name='{term}']").attrib
except Exception:
logging.error(f"Term {term} not found in translation file. Please add it to {translation_file}. Exiting.")
sys.exit(1)

translated_term = term_to_translate.get(publang)

if not translated_term:
logging.error(f"Translation for term '{term}' in language with code {publang} is missing. Please add it to {translation_file}. Exiting.")
sys.exit(1)
else:
return translated_term
# def translate ends here

0 comments on commit 61221ee

Please sign in to comment.