M src/hello_hut/greetings.py => src/hello_hut/greetings.py +4 -2
@@ 2,6 2,8 @@
import datetime
+from .translations import TRANSLATIONS
+
DEFAULT_NAME = "friend"
@@ 15,9 17,9 @@ def time_of_day_greeting(now=None):
return "Good evening"
-def greet(name=DEFAULT_NAME, shout=False, salutation=None):
+def greet(name=DEFAULT_NAME, shout=False, salutation=None, lang="en"):
"""Build a greeting such as "Hello, Ada!"."""
if salutation is None:
- salutation = "Hello"
+ salutation = TRANSLATIONS.get(lang, TRANSLATIONS["en"])
message = f"{salutation}, {name}!"
return message.upper() if shout else message
A src/hello_hut/translations.py => src/hello_hut/translations.py +17 -0
@@ 0,0 1,17 @@
+"""Salutations by language code.
+
+Keep the table sorted by code. Corrections from native speakers are very
+welcome; please send them to the devel list.
+"""
+
+TRANSLATIONS = {
+ "ar": "مرحبا",
+ "de": "Hallo",
+ "en": "Hello",
+ "es": "Hola",
+ "fr": "Bonjour",
+ "ja": "こんにちは",
+ "pt": "Olá",
+ "sv": "Hej",
+ "tr": "Merhaba",
+}