Implement a Pluralizing Message Formatter for Localized UI
Last updated: November 29, 2026
Quick Overview
Write `format_message(template, values, locale)` that fills `{name}` placeholders and supports `{count, plural, =0 {...} one {# item} other {# items}}` blocks, where `#` is replaced by the number and the plural category comes from a per-locale rule.
ZipHQ
November 29, 20260
0
0 solved
Write `format_message(template, values, locale)` that fills `{name}` placeholders and supports `{count, plural, =0 {...} one {# item} other {# items}}` blocks, where `#` is replaced by the number and the plural category comes from a per-locale rule.
Zip has written publicly about building its i18n infrastructure and migrating thousands of strings, and its users span many countries. This screen checks whether you understand why string concatenation breaks in translation and can implement the core of an ICU-style formatter cleanly.
What the Interviewer Expects
- Explain why `count + ' requests'` breaks for other languages
- Give exact matches like `=0` priority over plural categories
- Delegate the plural category to a locale rule rather than hardcoding English
- Fail loudly on a missing value instead of rendering a raw placeholder
- Mention that production code should use Intl.PluralRules or an ICU library
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you support nested placeholders inside a plural branch?
- How would you catch untranslated or malformed strings in CI?
- How do you format numbers and currency amounts inside the message per locale?
- How would you handle right-to-left languages in surrounding layout?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Support simple placeholders and one level of plural blocks. English uses one for 1, French uses one for 0 and 1. Exact =N branches win over categories; other is the fallback. Locale tags like ...
High-Level Design
One regex finds each placeholder with an optional plural body; a second regex splits the body into key {text} branches. A replacement function picks the branch and substitutes #. Plural rules are ...