Translate Messages by Known Keys
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Write createTranslator(messages), where messages maps each key to a message with {name}-style placeholders. It returns t(key, params), which looks the message up and replaces each placeholder with the param of that name (numbers too); a placeholder with no matching param stays as it is, and params can be left out. Type it so key must be one of the messages' keys and param values can only be strings or numbers.
Your code must pass
- Replaces placeholders with params
- Leaves unmatched placeholders alone
- Has no type errors
- Keys are the messages' keys
- Rejects an unknown key
- Params are strings or numbers