Architecture

Internationalization

Locales, URL routing, typed dictionaries, plurals, money and dates — and how to add a language.

Splitmize ships in Portuguese (default), English and Spanish. The whole system is about 150 lines in src/i18n/ and has no dependencies.

Routing

URLLocale
/, /split, /docs/…Portuguese
/en, /en/split, …English
/es, /es/split, …Spanish

All pages live under src/app/[locale]/. src/proxy.ts:

  • rewrites unprefixed paths to /pt/… internally (the URL stays clean);
  • redirects /pt/… to the unprefixed URL, so each page has one canonical address;
  • redirects an unprefixed visit to /en or /es only if the visitor explicitly picked that language before (cookie splitmize-locale, set by the language switcher).

There is deliberately no Accept-Language sniffing: crawlers and shared links should get what the URL says. Each page declares hreflang alternates in its metadata.

Dictionaries

src/i18n/dictionaries/pt.ts is the source of truth. Its shape defines the Dictionary type, and en.ts / es.ts are typed against it — a missing or extra key is a compile error, not a runtime surprise.

const { t, tp, tag } = useI18n();           // client components
const { t } = createTranslator(locale);     // server components

t('people.title')                           // "Quem tá na mesa?"
t('people.duplicate', { name: 'Ana' })      // interpolation with {name}
tp('receipt.people', 4)                     // "4 pessoas" — picks _one / _other

Keys are type-checked too: t('people.titel') doesn't compile.

Plurals

tp(key, count) looks up key_one or key_other using Intl.PluralRules. One deliberate deviation: CLDR files 0 under Portuguese "one" ("0 pessoa"), but people write "0 pessoas", so zero always uses _other.

Arrays

Structured copy (the landing page's steps, the features "menu") lives as arrays in the dictionary and is read directly from dict in Server Components.

Money and dates

Never format by hand. Use:

  • formatMoney(cents, currency, tag) → R$ 1.234,56, $1,234.56
  • formatAmount(...) → number only, for receipt columns
  • formatBillDate(iso, tag) → 14 nov 2026 · 21:40

tag is the BCP 47 tag from localeMeta (pt-BR, en-US, es).

Currency is independent of language. A new bill's currency is guessed from the browser language that matches the page language (pt-PT → EUR, es-MX → MXN), falling back to the language default (pt → BRL, en → USD, es → EUR). The choice is saved as the default for later bills.

Adding a language

  1. Add the code to locales and an entry to localeMeta in src/i18n/config.ts (label, short code, BCP 47 tag, Open Graph locale, default currency).
  2. Create src/i18n/dictionaries/<code>.ts typed as Dictionary — copy en.ts and translate. TypeScript will list anything you missed.
  3. Register it in src/i18n/translate.ts.
  4. Add the prefix to the proxy.ts matcher logic if it differs from the pattern (it reads locales, so usually nothing to do).
  5. Run npm run check and open /<code> and /<code>/split.

The docs

Documentation pages are written in English and rendered under every locale prefix with localized navigation. Their canonical URL points to the /en/docs/… version so search engines index one copy. A per-locale override system can be added in src/lib/docs.ts if translated docs are ever needed.

Edit this page on GitHub