Skip to content

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”.

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).

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.
src/i18n.ts
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;
}
src/locales/en.json
{
"greeting": "Hello, {name}!",
"save": "Save",
"cancel": "Cancel"
}
src/locales/fr.json
{
"greeting": "Bonjour, {name} !",
"save": "Enregistrer",
"cancel": "Annuler"
}

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.

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;
}

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.

Install the required plugin:

Terminal window
tynd add store
import { 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];
}

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.
  • 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.