Stipple

Localization

An app translated into a few languages needs to know which one the user reads, and to write numbers, amounts of money, dates and times the way the user's region does. Stipple reads the user's languages and formatting settings from the OS on every platform, formats with built-in tables that give the same result everywhere, picks plural forms by CLDR's rules, and has a small message catalog for the app's strings.

Live Localization The user's preferred languages, numbers, money, dates and times in their locale, plural forms from a message catalog, and a mirrored UI for Arabic and Hebrew. View source · Open full page
use stipple::locale::{Catalog, DateStyle, DateTime, negotiate};
use stipple::platform;

// The user's languages, most preferred first: ["fr-CA", "en-US"].
let languages = platform::preferred_languages();
// The best of the app's own languages for them: "fr".
let shown = negotiate(&languages, &["en", "fr", "ja"]).unwrap_or("en");

// Their conventions: French as written in Canada, with their clock.
let locale = platform::locale();
locale.format_number(1234.5);                      // "1 234,5"
locale.format_currency(9.99, "CAD");               // "9,99 $"
locale.format_date(&DateTime::now(), DateStyle::Long); // "16 novembre 2026"

// The app's strings, with plural forms.
let fr = Catalog::parse("fr", "notes.one = {count} note\nnotes.other = {count} notes")?;
fr.plural("notes", 3.0, &[]);                      // "3 notes"

The user's languages

platform::preferred_languages() returns BCP 47 tags ("fr-CA", "en-US", "zh-Hant-TW"), most preferred first, never empty ("en-US" when the OS says nothing):

PlatformRead from
macOS, iOSNSLocale.preferredLanguages
AndroidLocaleList.getDefault() (Android 7, API 24), else Locale.getDefault(), over JNI
WindowsGetUserPreferredUILanguages
LinuxLANGUAGE (gettext's list, unless the locale is C), then LC_ALL, LC_MESSAGES or LANG
Webnavigator.languages

Pick the language to show with locale::negotiate(&preferred, &shipped): the first preferred language with an exact match, else one matching on the language and script, else on the language alone (fr-CA gets fr, zh-TW gets zh-Hant). It returns None when nothing matches: fall back to the app's own language.

An app with a language setting of its own calls platform::set_preferred_languages(["ja"]): the chosen language comes first in preferred_languages(), platform::locale() uses it with the user's own clock and week, and the running app rebuilds (an empty list goes back to the OS's).

On iOS, the Settings app offers a per-app language only when the bundle's Info.plist lists more than one language in CFBundleLocalizations; preferred_languages() then starts with the one picked there.

Formatting

A Locale is a language and region's conventions. platform::locale() is the user's; Locale::new("de-CH") is any tag's, from the built-in tables.

Methoden-USfr-FRde-DEja-JP
format_number(1234567.891)1,234,567.8911 234 567,8911.234.567,8911,234,567.891
format_fixed(2.5, 2)2.502,502,502.50
format_percent(0.256)26%26 %26 %26%
format_currency(1234.5, "EUR")€1,234.501 234,50 €1.234,50 €€1,234.50
format_date(d, DateStyle::Short)11/16/2616/11/202616.11.262026/11/16
format_date(d, DateStyle::Medium)Nov 16, 202616 nov. 202616.11.20262026/11/16
format_date(d, DateStyle::Long)November 16, 202616 novembre 202616. November 20262026年11月16日
format_date(d, DateStyle::Full)Monday, November 16, 2026lundi 16 novembre 2026Montag, 16. November 20262026年11月16日月曜日
format_time(d, TimeStyle::Short)9:05 PM21:0521:0521:05
format_date_time(d, Long, Short)November 16, 2026 at 9:05 PM16 novembre 2026 à 21:0516. November 2026 um 21:052026年11月16日 21:05
  • Numbers are rounded to at most three decimals; format_fixed gives exactly as many as asked. The grouping follows the language (India's 12,34,567; Spanish and Polish leave four digits ungrouped) and Arabic writes Arabic-Indic digits (١٬٢٣٤), except in the Maghreb.
  • Currencies take their ISO 4217 code. Each has its usual decimals (none for the yen and the won, three for the Kuwaiti dinar) and the locale places the symbol and the minus sign: $1,234.50 at home and US$ abroad, € 1.234,50 in Dutch, R$ 10,00 in Brazil. Common currencies have a symbol; others show their code.
  • DateTime is a date and a time of day on the Gregorian calendar: DateTime::now(), DateTime::from_unix_local(secs) (the user's time zone), from_unix_utc, or a literal. format_pattern(d, "EEE d MMM") takes a CLDR pattern of your own; month_name, weekday_name, first_weekday and hour_cycle help draw a calendar.
  • Tags may carry Unicode extensions: -u-hc-h23 for the clock, -u-fw-mon for the first day, -u-rg-gbzzzz for another region's conventions, -u-nu-latn for ASCII digits.

Where the formats come from

Formatting always runs on Stipple's own tables, a subset of CLDR built into the crate: separators, number, percent and currency patterns, date and time patterns, month and weekday names, for English, French, German, Spanish, Italian, Portuguese, Dutch, Swedish, Russian, Ukrainian, Polish, Czech, Turkish, Japanese, Chinese, Korean, Arabic and Hebrew, with the regional differences that matter most (British, Canadian, Australian and Indian English, Canadian and Swiss French, Swiss and Austrian German, Mexican Spanish, European Portuguese, Traditional Chinese). Other languages get ISO-like dates (2026-11-16) and English names. The same Locale formats the same way on every platform, and tests use the tables.

The OS supplies what the user chose: platform::locale() starts from the tables for the user's region and lays the OS's settings on top.

PlatformRegionClockFirst weekdaySeparators, date and time formats
macOS, iOSNSLocale.currentLocale (language and region set apart, as en-FR)the locale's j patternNSCalendar.firstWeekdayNSLocale's separators, NSDateFormatter's patterns for each style, with the user's customizations
WindowsGetUserDefaultLocaleNamethe time formatLOCALE_IFIRSTDAYOFWEEKGetLocaleInfoEx: the decimal and thousands separators, the short and long date and time pictures (the long one is the full style here)
Androidthe first languageDateFormat.is24HourFormatCalendar.getFirstDayOfWeektables
LinuxLC_ALL, LC_TIME or LANGGNOME's clock-format, through the portaltablestables
Webthe first languageIntl.DateTimeFormat's hour cycleIntl.Locale's week infotables

Asking the OS to format each value (NSNumberFormatter, GetDateFormatEx, java.text, Intl) would give slightly different text on each platform and cost a call per value; reading its settings once, and its patterns where it keeps them, gives the user's choices with one formatter everywhere.

The tables cover what most apps show. For more (other calendars, compact numbers like "1.2K", relative times like "3 min ago", lists, units, collation) use icu4x with platform::preferred_languages()'s tags; fluent is the richer choice for message catalogs.

Plural forms

locale.plural(n) gives n's CLDR plural category: Zero, One, Two, Few, Many or Other. English uses One and Other; French puts 0 and 1.5 in One; Russian and Ukrainian have One (1, 21), Few (2–4, 22) and Many (5–20, 11); Arabic uses all six; Japanese, Chinese and Korean only Other. The rules cover about forty languages. plural_fixed(n, digits) matches format_fixed: "1.0 stars" is plural in English.

Message catalogs

A Catalog holds an app's strings in one language, from a small text format:

# Notes, in Russian
title = Заметки
greeting = Привет, {name}!
notes.one = {count} заметка
notes.few = {count} заметки
notes.many = {count} заметок
notes.other = {count} заметки
  • catalog.text("title"); catalog.format("greeting", &[("name", "Аня")]).
  • catalog.plural("notes", n, &[]) picks notes.<category> (else notes.other, else notes), and {count} is n formatted for the catalog's locale (set_locale(platform::locale()) for the user's separators).
  • \n is a line break, {{ and }} are braces.
  • .fallback(english) looks up keys a translation doesn't have yet; a key found nowhere comes back as is.

Embed the files with include_str! and pick one with negotiate:

let shown = negotiate(&platform::preferred_languages(), &["en", "fr", "ru"]).unwrap_or("en");
let en = Catalog::parse("en", include_str!("../i18n/en.txt"))?;
let tr = match shown {
    "fr" => Catalog::parse("fr", include_str!("../i18n/fr.txt"))?.fallback(en),
    "ru" => Catalog::parse("ru", include_str!("../i18n/ru.txt"))?.fallback(en),
    _ => en,
};

Right to left

The App mirrors the UI when the language it shows reads right to left (Arabic, Hebrew, Persian, Urdu…). It only knows which language that is once the app says which languages it ships: App::languages(["en", "fr", "he"]). The direction then follows the language the user gets, so an app shipping only English stays left to right on an Arabic system. Without it, the UI is never mirrored, since its language is unknown. A theme with its own layout_direction keeps it (Theme::follows_locale is then off). See bidi.md.

Following changes

When the user's languages or formats change while the app runs, the event loop delivers Event::LocaleChanged, and the App works the direction out again, calls App::on_locale_change(|state, locale| …) and rebuilds its views, so a view reading platform::locale() shows the new formats.

PlatformHeard from
macOSNSCurrentLocaleDidChangeNotification (region, languages, clock, formats)
iOSNSCurrentLocaleDidChangeNotification (region, clock); a new language restarts the app
Androidthe configuration change, with locale|layoutDirection in the manifest's configChanges (see Android); the clock and first day are read again when the app comes back to the foreground
WindowsWM_SETTINGCHANGE for intl
LinuxGNOME's clock-format through the portal; the environment is fixed for the process
Weblanguagechange

Stipple's own strings

A message box with no buttons given shows "OK" in the user's language ("Aceptar", "确定", "אישור"), and iOS's accessibility values ("on", "checked", "expanded"…) are translated into the eighteen languages above. Buttons and labels an app passes are shown as they are.

View this page on GitHub