Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add translation from norwegian label to english label #84

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ venv
config.json
src/config.json
.idea
.venv
5 changes: 5 additions & 0 deletions src/webapp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ def get_example_drawings(json_data):
data = json.loads(json_data)
game_id = data["game_id"]
number_of_images = data["number_of_images"]

label = data["label"]
lang = data["lang"]
if (lang == "NO"):
label = models.to_english(label)

example_drawings = storage.get_n_random_images_from_label(
number_of_images, label)
emit("getExampleDrawings", json.dumps(example_drawings), room=game_id)
Expand Down
14 changes: 14 additions & 0 deletions src/webapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,20 @@ def to_norwegian(english_label):
)


def to_english(norwegian_label):
"""
Reads the labels table and return the english translation of the norwegian label
"""
try:
query = Labels.query.filter(Labels.norwegian == norwegian_label)[0]
return str(query.english)

except AttributeError as e:
raise AttributeError(
"Could not find translation in Labels table: " + str(e)
)


def seed_labels(app, filepath):
"""
Function for updating labels in database.
Expand Down
Loading