i18n

Summary

Soma localizes its own interface strings, the 41 texts the components render themselves: the date picker's footer buttons, presets and aria-labels, dismiss/loading labels, the RESTful table's verbs, tree toggles, dialog and palette chrome, the dropzone prompts, the navbar's More menu. Month names, weekday names, and the first day of the week come from the browser's Intl data, so every language works there without a translation file. 42 locale packs ship built in: every EU official language, the Nordics, and the most-used world languages (see the list below); anything else registers a 41-key pack.

Application text is deliberately out of scope: on server-rendered pages that belongs to the server's own resource bundles. The date input format also stays ISO (YYYY-MM-DD): it's a data contract, not a display string.

Locale selection

SourceNotes
Soma.i18n({ locale: 'cs' })Explicit: wins over everything. Set it before components render; strings are baked at construction and existing DOM is not re-rendered.
<html lang="cs">The normal server-rendered path: the server sets one attribute and Soma follows.
(neither)English.

Locale codes are case-insensitive, and regional codes fall back to their base language: cs-CZ uses the cs pack (an exact regional pack, if registered, wins), and zh-TW/zh-HK/zh-MO resolve to Traditional Chinese. Per-key overrides win over the active pack; anything still missing falls back to English. Soma.i18n({ locale: null }) clears an explicit locale and returns to <html lang> detection.

Examples

Live locale switcher

Switch locale, then open the date picker or spawn a toast; new components render in the chosen language:

Note what the toast demo shows: its title and body are application content: the demo script translates them itself, keyed off Soma.i18n().locale, exactly as a real app would. The only toast string Soma itself localizes is the dismiss button's aria-label ("Dismiss notification" / "Zavřít"; inspect the × to see it).

Open the date field after switching: weekday and month names come from Intl, the Today/Clear buttons and aria-labels from the pack.

JavaScript API

MemberDescription
Soma.i18n({ locale })Switch locale (null returns to <html lang>/English).
Soma.i18n({ messages: {…} }) or Soma.i18n({ 'datePicker.today': '…' })Per-key overrides: they win over the active pack. Unknown keys throw (a typo fails loudly). messages: null clears all overrides.
Soma.i18n.register(code, pack)Add or extend a locale pack; merges, so partial packs are fine: missing keys fall back to English. Any BCP-47 code works, including private-use tags.
Soma.i18n.locales()The built-in locale codes.
Soma.i18n()Reads state: { locale, messages }.
Soma.i18n({ locale: 'cs' });                  // pick a built-in pack
Soma.i18n();                                  // → { locale, messages }
Soma.i18n({ 'datePicker.today': 'Nyní' });    // override single keys
Soma.i18n.locales();                          // → the built-in locale codes

// Add a language — partial packs fall back to English per key:
Soma.i18n.register('de', {
  'datePicker.today': 'Heute',
  'datePicker.clear': 'Löschen',
  'datePicker.chooseDate': 'Datum wählen',
  'datePicker.previousMonth': 'Voriger Monat',
  'datePicker.nextMonth': 'Nächster Monat',
  'datePicker.hour': 'Stunde',
  'datePicker.minute': 'Minute',
  'toast.dismiss': 'Schließen',
  'select.searchOptions': 'Optionen durchsuchen',
  'select.clearSelection': 'Auswahl löschen',
  'select.noMatches': 'Keine Treffer',
  'restfulTable.noEntries': 'Keine Einträge',
  'restfulTable.loading': 'Laden',
  'sidebar.resize': 'Seitenleiste anpassen',
  // …any keys you leave out stay English
});
Soma.i18n({ locale: 'de' });

Built-in locales

en (fallback catalog) plus 42 packs — every EU official language, the Nordics, and the most-used world languages:

    One caveat: the packs are machine-translated standard UI vocabulary awaiting native-speaker review. Serbian ships in Cyrillic: register a sr-Latn pack if you prefer latinica; no resolves to Bokmål (nb).

    Right-to-left (RTL) layout

    Soma fully supports RTL: set dir="rtl" on <html> (or any subtree) and everything mirrors: layout and components (CSS logical properties), popover alignment, drag directions, and keyboard semantics (horizontal arrows follow visual direction in tabs and the date-picker grid, per ARIA practice). Combined with the ar, fa, he, and ur packs, those languages are supported end to end. Try it live: the direction button in the bottom-right corner flips this whole docs site.

    String catalog

    KeyEnglishCzech (built in)Used by
    datePicker.todayTodayDnesdate picker
    datePicker.clearClearVymazatdate picker
    datePicker.chooseDateChoose dateVyberte datumdate picker (aria)
    datePicker.previousMonth / .nextMonthPrevious/Next monthPředchozí/Další měsícdate picker (aria)
    datePicker.hour / .minuteHour / MinuteHodina / Minutadate picker (aria)
    dateRange.last7 / .last30Last 7 days / Last 30 daysPosledních 7 dní / Posledních 30 dnídate-range presets
    dateRange.thisMonth / .lastMonthThis month / Last monthTento měsíc / Minulý měsícdate-range presets
    toast.dismissDismiss notificationZavříttoasts (aria)
    banner.dismissDismiss bannerZavřítbanners (aria)
    message.dismissDismissZavřítmessages (aria)
    select.searchOptionsSearch optionsHledat možnostiselect (aria)
    select.clearSelectionClear selectionVymazat výběrselect (aria)
    select.noMatchesNo matchesŽádné shodyselect
    combobox.noSuggestionsNo suggestionsŽádné návrhycombobox
    dropzone.browseDrag and drop files here, or browsePřetáhněte soubory sem, nebo procházejtedropzone (generated prompt)
    dropzone.rejectNot accepted: {names}Nepřijato: {names}dropzone (alert)
    dropzone.removeRemove {name}Odebrat {name}dropzone (aria)
    restfulTable.noEntriesNo entriesŽádné záznamyRESTful table
    restfulTable.loadingLoadingNačítáníRESTful table
    restfulTable.edit / .delete / .update / .add / .cancelEdit / Delete / Update / Add / CancelUpravit / Smazat / Aktualizovat / Přidat / ZrušitRESTful table
    restfulTable.operationsOperationsAkceRESTful table (header)
    tree.expand / .collapseExpand / CollapseRozbalit / Sbalittree (aria)
    spinner.loadingLoadingNačítáníspinner (aria)
    sidebar.resizeResize sidebarZměnit šířku panelusidebar (aria)
    navbar.moreMoreVíceresponsive navbar
    breadcrumbs.moreMoreVícecollapsed breadcrumbs (aria)
    dialog.confirm / .cancel / .okConfirm / Cancel / OKPotvrdit / Zrušit / OKSoma.confirm / Soma.alert buttons
    palette.labelCommand palettePaleta příkazůcommand palette (aria)
    palette.placeholderType a command…Zadejte příkaz…command palette
    palette.emptyNo matching commandsŽádné odpovídající příkazycommand palette

    What Intl covers automatically

    For the active locale the date picker derives month names, short weekday names, and the first day of the week from Intl.DateTimeFormat / Intl.Locale — no dictionary involved. A per-instance Soma.datePicker(input, { locale }) option still overrides the global locale where needed. Locale tags Intl rejects (e.g. private-use x-…) fall back to English names rather than failing.

    Easter eggs 🖖

    To prove Soma.i18n.register() handles anything with a BCP-47 code, this page registers three extra locales: Klingon (tlh, a real ISO 639-2 code; vocabulary after Okrand), Sumerian (sux, reconstructed from attested roots; the previous/next month labels honor the Sumerian conception that the past lies before you, igi, and the future behind, egir), and Hobbitish (x-hobbit: Westron has no ISO code, so it demonstrates a private-use BCP-47 tag; and since Tolkien rendered Westron as English, the pack is proper Shire-speech). Pick them at the bottom of the locale dropdown above. None of them ship in the library bundle, and Intl has no calendar data for them, so month names fall back, exactly the graceful degradation a custom locale gets. (The Shire Reckoning — Afteryule, Solmath, Rethe… — must wait for a custom-month-names date-picker option.)