From 9f8484417d6f34e79f6fc64c0a3521fd80235c8f Mon Sep 17 00:00:00 2001 From: Noor Haddad Date: Tue, 6 Oct 2026 10:02:00 +0300 Subject: [PATCH] greetings: add a translation table --- src/hello_hut/greetings.py | 6 ++++-- src/hello_hut/translations.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/hello_hut/translations.py diff --git a/src/hello_hut/greetings.py b/src/hello_hut/greetings.py index 3b776fc5ad6543f49e7096c37eefb9b91df3f2ad..dc3fda63557f67f87bc8f0916fd557af9db0fd95 100644 --- a/src/hello_hut/greetings.py +++ b/src/hello_hut/greetings.py @@ -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 diff --git a/src/hello_hut/translations.py b/src/hello_hut/translations.py new file mode 100644 index 0000000000000000000000000000000000000000..b44b1155d38f1d04ba13b3b8e85e66520782e7cb --- /dev/null +++ b/src/hello_hut/translations.py @@ -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", +}