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
Software Engineering Fundamentals
Frontend Engineer
ZipHQ
November 29, 2026
Frontend Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

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
internationalization
ICU message format
plural rules
regular expressions
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported

Related Questions