Aperture UI
Content development

Localization

ICU and Intl, right-to-left text, shaping, fonts and recommended patterns for translated game UI in Aperture UI.

Aperture UI has no translation system. You bring your strings and your language choice. The engine supplies the parts that depend on locale data: V8's Intl with ICU, a text shaper that handles complex scripts and bidirectional text, and fallback fonts. Unicode bidirectional text and complex script shaping are handled by the vendored Skribidi text library, not by ICU. This page covers each part, and the places where a localized page needs care.

Text Shaping and Locale-Sensitive Formatting

FeatureMechanism
BiDi (RTL/LTR) textSkribidi's bidirectional algorithm, and layout direction from the CSS direction property (not the dir attribute)
Arabic shapingAutomatic via the vendored Skribidi shaping engine
CJK renderingFont glyph lookup, with line breaks at the positions the Unicode line-break rules allow
Indic shapingAutomatic for fonts that include the required tables
Regional glyph formsThe nearest lang or xml:lang attribute, passed to the shaper
Locale-sensitive number formattingIntl.NumberFormat
Locale-sensitive date formattingIntl.DateTimeFormat
Collation (sorting strings)Intl.Collator
Plural rulesIntl.PluralRules

Set lang on the document or on an element. The shaper uses it to choose locale-specific glyph forms, such as the regional forms of Han characters that Chinese, Japanese and Korean share.

<html lang="ja">
  <body>
    <p>ゲーム開始</p>
  </body>
</html>

ICU Data and Intl

V8 runs with ICU, so Intl formatting and collation work as they do in V8 15.6.75.12. They need V8's ICU data next to the V8 snapshot, in resources/. Ship both files:

  • resources/icudtl.dat. Startup validation (validateResourcesOnInit, on by default) requires this file.
  • resources/v8_icudtl.dat. The same data under a name no other library uses. When it is present, ICU loads it in preference to icudtl.dat.

A missing or wrong ICU file does not degrade gracefully

A missing file makes startup validation, or V8's own initialization, fail. IAPCPlatform::InitializeJavaScriptEngine() reports an error and no script runs: a view logs that the JavaScript engine is not initialized and skips creating its isolate. There is no fallback to ASCII or English. A file from another ICU version is worse. CEF ships an icudtl.dat of a different version, and if it is the only one in the folder, ICU loads it and the first Intl or toLocale* call aborts the process. Shipping v8_icudtl.dat keeps another library's icudtl.dat in the same folder from taking its place. Requirements lists the files.

new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(1234.5);
new Intl.NumberFormat("ar-EG").format(1234567);
new Intl.DateTimeFormat("ja-JP", { dateStyle: "full" }).format(new Date());
new Intl.PluralRules("ru-RU").select(2); // "few"

The language is yours to supply. navigator.language is always en-US and navigator.languages holds only that value. Pass the player's language from your game, for example in the data model (see Data binding) or as an argument to a function the page defines, and give Intl an explicit locale.

Use Intl.PluralRules to pick the correct grammatical form when interpolating counts, instead of appending an s:

const rules = new Intl.PluralRules('en-US');
const messages = {
  one:   '1 enemy remaining',
  other: '{n} enemies remaining',
};
const text = messages[rules.select(count)].replace('{n}', count);

Right-to-Left Support

Right-to-left layout is driven by the CSS direction property:

.arabic-section { direction: rtl; }
<html lang="ar" style="direction: rtl">
  <body>
    <h1>أهلا بالعالم</h1>
  </body>
</html>

Skribidi shapes Arabic and Hebrew, its embedded SheenBidi drives the bidirectional algorithm, and the visual order of text is correct. The engine's tests cover direction: rtl on inline content and on logical properties.

  • Use direction, not the dir attribute. The HTML dir attribute is matched by the :dir() selector and readable from script, but this version does not turn it into direction. Set direction: rtl in CSS on the root element instead.
  • <bdi> and unicode-bidi have no special handling. unicode-bidi is not a registered property and <bdi> has no user-agent rule, so mixed-direction text, such as a player name inside a sentence, relies on the bidirectional algorithm alone.
  • Flexbox and grid do not mirror. The flex and grid layout code does not read direction, so flex-direction: row still runs left to right inside an RTL container, and grid-template-columns still starts from the left. Reverse such rows yourself with row-reverse or order, and check each layout in the language it ships in.

Logical CSS Properties

Logical properties mirror under direction: rtl. They resolve against the element's own direction, and so do the start and end values of text-align. Prefer them to left and right so that one stylesheet serves both directions:

PhysicalLogical
margin-leftmargin-inline-start
margin-rightmargin-inline-end
padding-leftpadding-inline-start
border-left-widthborder-inline-start-width
leftinset-inline-start
widthinline-size
text-align: lefttext-align: start

The block-axis and shorthand forms (margin-inline, padding-inline, block-size) exist too.

Translation Patterns

Aperture UI does not include a built-in translation system, so you bring your own. Two common patterns:

A Page Function and data-i18n

Keep your dictionaries as JSON in your asset pipeline, one per language:

// translations/en.json
{ "menu.start": "Start Game", "menu.options": "Options" }

// translations/ja.json
{ "menu.start": "ゲーム開始", "menu.options": "オプション" }

Mark each translatable element, define one function in the page that applies a dictionary, and have the host call it with the player's language:

<button data-i18n="menu.start"></button>
window.setStrings = (strings) => {
  document.querySelectorAll("[data-i18n]").forEach((el) => {
    el.textContent = strings[el.getAttribute("data-i18n")] ?? "";
  });
};
view.callJavaScriptFunctionJson("setStrings", R"({"menu.start":"ゲーム開始"})");

Strings from the Host

Publish the strings as a data model and bind them. Switching language is one more setDataModel call:

<button data-bind-value="{{ui.start}}"></button>
view.setDataModel("ui", R"({"start":"ゲーム開始"})");

Every binding that reads ui updates. The binding expression has to begin with the model name. See Data binding.

For live-service games where translations update over the air, push the translation tables from the server through your game's existing data sync layer, then use either pattern above.

Font Considerations

Translations only render correctly if the active font has the required glyph coverage. The bundled fallback set covers a limited number of scripts, and on platforms other than Windows nothing else is available:

  • Bundle a fallback font with broad coverage (the Noto Sans family) for Latin extended ranges
  • Ship a CJK font for Japanese, Chinese and Korean releases
  • Ship a font for each other script you release in, and name it in font-family after your Latin fonts
  • Test every locale with the actual game build, not a browser preview

See Fonts for how the engine picks and falls back, and for the Windows-only system fonts.

Testing Translations

  • Test with the real engine and the real fonts. A browser preview uses different fonts and a different text engine.
  • Pseudo-localize your strings (turn each English string into [!! Stârt Gãmę !!]) to find clipped text before the translations arrive.
  • Use a right-to-left pseudo-localization to catch direction issues, and test with a right-to-left language if you ship one.
  • Test with the longest expected translation for each slot. German is a notorious expander over English.

On this page