Skip to content

Commit

Permalink
feat: add translation from norwegian label to english label
Browse files Browse the repository at this point in the history
  • Loading branch information
sondrefj committed Jul 16, 2024
1 parent a4223c8 commit 352c6e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
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

0 comments on commit 352c6e5

Please sign in to comment.