Skip to content

Commit

Permalink
Merge pull request #188 from Felienne/parse-lang
Browse files Browse the repository at this point in the history
fix: `parse` always uses browser language (instead of selected language)
  • Loading branch information
Felienne authored Feb 25, 2021
2 parents 91cda49 + caedf56 commit e68acd7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def parse():

code = body ['code']
level = int(body ['level'])
# Language should come principally from the request body,
# but we'll fall back to browser default if it's missing for whatever
# reason.
lang = body.get('lang', requested_lang())

# For debugging
print(f"got code {code}")
Expand All @@ -109,7 +113,7 @@ def parse():
# is so, parse
else:
try:
hedy_errors = TRANSLATIONS.get_translations(requested_lang(), 'HedyErrorMessages')
hedy_errors = TRANSLATIONS.get_translations(lang, 'HedyErrorMessages')
result = hedy.transpile(code, level)
response["Code"] = "# coding=utf8\n" + result
except hedy.HedyException as E:
Expand All @@ -130,7 +134,7 @@ def parse():
'session': session_id(),
'date': str(datetime.datetime.now()),
'level': level,
'lang': requested_lang(),
'lang': lang,
'code': code,
'server_error': response.get('Error'),
'version': version(),
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ui:
assignment_header: "Exercice"
ClientErrorMessages:
Transpile_warning: "Attention!"
Transpile_error: "Le serveur n’a pas pu traduire ce code Heyd en Python."
Transpile_error: "Le serveur n’a pas pu traduire ce code Hedy en Python."
Connection_error: "Nous n’avons pas réussi à contacter le serveur."
Other_error: "Oups! Nous avons rencontré une erreur."
Execute_error: "Quelque chose s’est mal passé en exécutant ce programme."
Expand Down

0 comments on commit e68acd7

Please sign in to comment.