Your question is Format Localized App Messages. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
A global mobile app stores message templates for different locales. Implement a formatter that selects the best available localized template and replaces placeholders with provided values.
Write a function format_message(translations, locale, key, params) that returns the formatted string for a message key.
translations: a dictionary where each locale maps to another dictionary of message keys to template stringslocale: a locale string such as "en-US" or "fr-CA"key: the message key to renderparams: a dictionary of placeholder names to replacement valuesen for en-US)enkey if no template existsPlaceholders use {name} syntax. Replace only placeholders present in params; leave unknown placeholders unchanged.
-{placeholder} syntaxdef format_message(translations, locale, key, params):