Internationalization
Tynd exposes the OS locale via os.locale() and the dark-mode preference via os.isDarkMode(). Beyond that, i18n is just “pick a library and go”.
Detect the user’s locale
Section titled “Detect the user’s locale”import { os } from "@tynd/core/client";
const locale = (await os.locale()) ?? "en"; // "en-US", "fr-FR", "ja-JP", …os.locale() returns Promise<string | null> — null if the platform doesn’t expose a locale tag. Always fall back. BCP-47 tag, matches what the OS reports. Read at app startup; re-read if you support “language” preference changes (OS-level language changes require app restart on all three OSes).
UI strings — pick a lib
Section titled “UI strings — pick a lib”Any pure-JS i18n library works:
| Lib | Size | Notes |
|---|---|---|
i18next |
~40 KB | Ecosystem leader. React-i18next, Vue-i18n integrations. |
format-message |
~15 KB | ICU MessageFormat syntax. |
@lingui/core |
~10 KB | Lightweight; compile-time extraction. |
| Rolling your own | ~0 KB | Flat JSON + a t("key") function — fine for small apps. |
Minimal roll-your-own
Section titled “Minimal roll-your-own”import { os } from "@tynd/core/client";import en from "./locales/en.json";import fr from "./locales/fr.json";
const catalogs: Record<string, Record<string, string>> = { en, fr };
let currentLocale = "en";
export async function initI18n() { const full = (await os.locale()) ?? "en"; const short = full.split("-")[0]; currentLocale = catalogs[short] ? short : "en";}
export function t(key: string, vars?: Record<string, string>) { let s = catalogs[currentLocale][key] ?? key; if (vars) { for (const [k, v] of Object.entries(vars)) { s = s.replace(`{${k}}`, v); } } return s;}{ "greeting": "Hello, {name}!", "save": "Save", "cancel": "Cancel"}{ "greeting": "Bonjour, {name} !", "save": "Enregistrer", "cancel": "Annuler"}Dates + numbers
Section titled “Dates + numbers”Bun runtime
Section titled “Bun runtime”Intl.DateTimeFormat, Intl.NumberFormat, Intl.RelativeTimeFormat, Intl.Collator, and Intl.Segmenter are available through Bun.
const formatter = new Intl.DateTimeFormat("fr-FR", { dateStyle: "long" });formatter.format(new Date()); // "25 avril 2026"Libraries such as date-fns and numbro remain useful when you want explicit locale bundles or deterministic formatting.
RTL layouts
Section titled “RTL layouts”The WebView handles dir="rtl" natively:
<html lang="ar" dir="rtl">Toggle at runtime by setting document.dir = "rtl" | "ltr" when the user switches language.
CSS logical properties make this easier:
.card { padding-inline-start: 1rem; /* margin-left in LTR, margin-right in RTL */ border-inline-end: 1px solid #ccc;}Plurals
Section titled “Plurals”ICU MessageFormat ({count, plural, one {# item} other {# items}}) is the standard. format-message, i18next, @lingui/core all support it. Rolling your own for plurals is harder than for basic substitution — reach for a lib.
Persisting the user’s choice
Section titled “Persisting the user’s choice”Install the required plugin:
tynd add storeimport { createStore } from "@tynd/plugin-store/client";
const prefs = createStore("com.example.myapp");
export async function setLanguage(lang: string) { await prefs.set("lang", lang); currentLocale = lang; // re-render the app}
export async function initI18n() { const saved = await prefs.get<string>("lang"); const full = (await os.locale()) ?? "en"; currentLocale = saved ?? full.split("-")[0];}OS-integrated surfaces
Section titled “OS-integrated surfaces”Some UI is system-rendered and uses the OS language regardless of your app’s preference:
- Native dialogs (
dialog.openFile,dialog.confirm) — button labels (“Open”, “Save”, “Cancel”) come from the OS. - System tray — OS-native.
- Notifications — your title/body are shown as-is, but “Quit” on an interactive notification (if you add one in a future release) uses the OS language.
- Auto-update — you control the user-facing strings; OS-level installer dialogs (MSI, notarization on macOS) are OS-localized.
Accessibility intersects
Section titled “Accessibility intersects”- Screen readers read text in the page’s
lang. Set<html lang>correctly or VoiceOver / Narrator may mispronounce. - RTL users expect RTL focus order — use logical CSS, not hard-coded left/right.
See Accessibility.
Related
Section titled “Related”- os.locale API.
- Runtimes — what’s in
Intlper runtime.