diff --git a/exercises/testing-code/README.md b/exercises/testing-code/README.md index 44a4a66..6024ffd 100644 --- a/exercises/testing-code/README.md +++ b/exercises/testing-code/README.md @@ -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 diff --git a/utilities/microservice/microservice.py b/utilities/microservice/microservice.py index 4dbd344..7e66973 100644 --- a/utilities/microservice/microservice.py +++ b/utilities/microservice/microservice.py @@ -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"}, } @@ -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}")