Skip to content

svelte-dialect

Tiny MessageFormat 2 i18n for Svelte 5 and SvelteKit.

Runes instead of stores, namespaced keys, SSR locale negotiation, URL routing and typed message keys — in a library small enough to read in one sitting. This site is also the demo: it runs on the exact setup described here, prefix and all.

Built on MessageFormat 2 — rich text lands as snippets, not string concatenation

Quickstart #

The core of it: create the dialect once and wire two hooks. The full path, from install to the first translated line, is on the Setup page.

src/lib/i18n.ts
import { createDialect } from 'svelte-dialect/kit';

export const { t, handle, reroute, localizeHref, locales } = createDialect({
	messages: import.meta.glob('./messages/**/*.json', { eager: true }),
	defaultLocale: 'en',
	routing: true
});
src/hooks.server.ts
import type { Handle } from '@sveltejs/kit/hooks';
import { handle as dialect } from '#lib/i18n.js';

export const handle: Handle = dialect;
src/hooks.ts — universal, not hooks.server.ts
import type { Reroute } from '@sveltejs/kit/hooks';
import { reroute as dialect } from '#lib/i18n.js';

export const reroute: Reroute = dialect;
Full setup, step by step →

Try it #

Hello, Svelte!

You clicked 0 times

Plural categories come from the locale, not from the library. Switch to Russian and the same message picks one / few / many.

Where to go next #