Skip to content
Closed
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
2 changes: 1 addition & 1 deletion exercises/testing-code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ invoking properly. Now it is time to test if Goodbye is also working.
2. Copy the tuple in the `pytest.mark.parametrize` list and paste it into the
list, effectively creating a second entry to test the method on.
3. Change the term for the `TranslationActivityInput` object in this second
tuple from `Hello` to `Goodbye`
tuple from `hello` to `goodbye`
4. Change the language code for the `TranslationActivityInput` object in this
second tuple from `de` (German) to `lv` (Latvian)
5. Change the translation for the `TranslationActivityOutput` object in this second
Expand Down
12 changes: 8 additions & 4 deletions utilities/microservice/microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"mi": {"hello": "kia ora", "goodbye": "poroporoaki", "thanks": "whakawhetai koe"},
"sk": {"hello": "ahoj", "goodbye": "zbohom", "thanks": "ďakujem"},
"tr": {"hello": "merhaba", "goodbye": "güle güle", "thanks": "teşekkür ederim"},
"zu": {"hello": "hamba kahle", "goodbye": "sawubona", "thanks": "ngiyabonga"},
"zu": {"hello": "sawubona", "goodbye": "hamba kahle", "thanks": "ngiyabonga"},
}


Expand All @@ -30,13 +30,17 @@ def translate():
if not lang:
return jsonify({"error": "Missing required 'lang' parameter"}), 500

if lang not in translations:
# Match terms and language codes case-insensitively (e.g., "Hello" or "HELLO")
lang_key = lang.lower()
term_key = term.lower()

if lang_key not in translations:
return jsonify({"error": f"Invalid language code '{lang}'"}), 500

if term not in translations[lang]:
if term_key not in translations[lang_key]:
return jsonify({"error": f"Invalid translation term '{term}'"}), 500

translation = translations[lang][term]
translation = translations[lang_key][term_key]
capitalized_translation = translation.capitalize()

print(f"{term} translated to {lang} with result {translation}")
Expand Down
Loading