One Game Page, 11 Languages: Fonts, Plurals and Button Fit
Each Play5s game page ships in 11 languages from one codebase, and three things keep it from breaking. Language-specific CSS swaps the font stack and line-breaking rules for Japanese, Korean and Russian. Plural forms come from Intl.PluralRules, not hand-written conditions. And the control bar is measured after fonts load, then shrunk step by step until the longest translation fits. English never changes.
This note covers how a game screen is displayed in each language, not how pages are written.
How does the page choose a font for each language?
The self-hosted fonts cover Latin text only: Atkinson Hyperlegible for reading and Bungee for signs and buttons. Japanese, Korean and Russian pages would show missing glyphs or an arbitrary fallback, so they take over with system stacks. The page defines two custom properties, one for reading text and one for signs, and redefines them per language with the :lang() selector:
/* shortened: the real stacks list a few more system fonts */
html:lang(ja) { --read: "Atkinson Hyperlegible", "Hiragino Sans", "Yu Gothic UI", Meiryo, "Noto Sans JP", system-ui, sans-serif;
--sign: "Hiragino Sans", "Yu Gothic UI", Meiryo, "Noto Sans JP", system-ui, sans-serif; }
html:lang(ko) { --read: "Atkinson Hyperlegible", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif; }
html:lang(ru) { --read: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; }
The Latin face stays first in the reading stack, so digits and Latin names look the same everywhere, and the browser falls through to a system font for each character the web font lacks. The sign face is replaced outright, since Bungee has no kana, hangul or Cyrillic and a heavy sans from the system is a better partner than a half-covered display font. A game screen can be shown in a different language than the page around it, so the same rules are repeated for the stage element.
Two smaller font details. Atkinson draws its zero with a slash, and in running text it made "104 cards" read as "1Ø4 cards". A one-glyph face called P5 Zero, limited to the zero character with unicode-range, is placed first in the page text stack, while the game screens keep the slashed zero. And while a web font loads, a system face scaled with size-adjust to the web font's width stands in, so the swap does not re-wrap a paragraph.
How do Japanese and Korean text break lines?
Japanese and Korean do not rely on spaces the way English does, so the defaults need help. Two rules sit on the root element:
html:lang(ko) { word-break: keep-all; overflow-wrap: anywhere; }
html:lang(ja) { line-break: strict; word-break: auto-phrase; overflow-wrap: anywhere; }
MDN's page for word-break says keep-all stops word breaks inside Chinese, Japanese and Korean text, which keeps a Korean word such as 무료 whole. auto-phrase adds language-specific analysis so breaks avoid the middle of a natural phrase. MDN still marks it experimental, so a browser without it just ignores the declaration and behaves as normal. For line-break, strict applies the most stringent rules, which for Japanese keeps small kana from starting a line. The W3C's Japanese and Korean layout requirements explain the reasons behind these rules.
overflow-wrap: anywhere is the safety net for all languages. German and Swedish compounds, and game names in narrow boxes, wrap instead of widening the page. We left hyphens: auto off headings, because it would re-break English headings that fit.
How do plural forms work in Russian, Japanese and Korean?
English has two plural forms. Russian has three for whole numbers. The Unicode CLDR plural rules define the categories per language: in Russian one covers 1, 21, 31, few covers 2 to 4 and 22 to 24, and many covers 0, 5 to 19 and 100. Japanese and Korean have only other.
Instead of writing conditions per language, dictionary strings carry a small subset of the ICU message format:
en "{n, plural, one {# move} other {# moves}}"
ru "{n, plural, one {# ход} few {# хода} many {# ходов} other {# хода}}"
ja "{n, plural, other {#手}}"
A 59-line module fills such a string. It substitutes {name} variables first, then for each plural block it asks Intl.PluralRules for the category of the number, with an exact =0 branch checked before the category. Numbers are written as plain digits with no thousands separator, so the English text stays exactly as it was. The categories come from the browser's CLDR data, which is why the table of languages never appears in our code.
The dictionaries are checked at build time. Every language must hold every key, and a key must use the same variables everywhere, including variables inside plural branches, so a translator who drops {n} breaks the build with the file name and key in the error.
What happens when a translated button is longer?
Labels change length by language. "Moves" becomes "Movimientos" in Spanish, a mode button reads "3 Durchgänge" in German and "Z zawijaniem" in Polish, and the same screen has to fit at 320 pixels. Fixed widths and guesses fail, so the page measures. A script on every game page looks at the control row and, while it overflows, adds one more step:
- Undo and Hint show only their icons, which narrow phones already did.
- New and Finish do the same.
- Gaps and padding tighten, and the mode button drops its icon.
- The mode label shrinks, whole, in half-pixel steps down to 8 px. It is never cut.
const over = () => row.scrollWidth > row.clientWidth + 1
|| row.getBoundingClientRect().right > document.documentElement.clientWidth;
for (const k of ['kl-fit1', 'kl-fit2', 'kl-fit3']) { if (!over()) break; hud.classList.add(k); }
if (mode && over()) { hud.classList.add('kl-fit4'); /* then shrink the label to 8 px */ }
The statistic tiles (Time, Moves, Score, Best) have their own ladder. A long label shrinks to 8 px, then the tile drops its little clock icon, then the four tiles share the row by content instead of equally, and only as a last resort does a label end in an ellipsis, with the full word moved to the tile's title. The one-pixel tolerance matters: English "TIME" at 320 pixels spills a sub-pixel and must not count as a cut.
The fit runs again whenever something can change it: on resize through a ResizeObserver, when a button is shown or hidden or a label changes through a MutationObserver, and when document.fonts.ready resolves, because a late font changes every width. The function only touches classes on the bar and one button's inline size, which are outside the observer's filter, so it cannot wake itself. English at the sizes it was tuned for never overflows, so it gets no step and keeps its original look.
Where did the language list go?
Not into the bar. A control bar with one more button cut the stat labels on 320 pixel phones, so the list of languages lives inside the settings panel that the gear button already opens, as a group of links, each written in its own language. A language the game page already exists in switches to that page, and the game can also be shown in a language without leaving the page.
To see the finished screens, open the games with screens in Japanese or the same ones with screens in Korean and pick one: the fonts, the line breaks and the plural forms in the counters are the ones described here.
How do we test it?
A browser test opens every page that exists in each language and checks that the language attribute is right, that no English interface text remains on a translated game screen, and that internal links go to pages in the same language. It then measures every control label and stat tile at 320, 360, 390, 414 and 768 pixels and fails if one does not fit, and checks for sideways scrolling at 320, 390 and 1440 pixels. A second test sweeps the header across 11 languages and 21 widths: one row, fixed height, no overlap. The fit steps exist because those tests showed longer translations overflowing, and they also fixed a few English screens that had been cut at 414 and 320 pixels.