Zum Hauptinhalt springen

Sprachwahl

Erkennungsreihenfolge: URL-Präfix → Cookie → Basissprache (Englisch)

Aktuelle Sprache: Deutsch (de)
Formatting locale: de-DE

Übersetzte Nachrichten

m.greeting({ name: 'World' }) Hallo, World!
m.welcome_message() Willkommen bei der Internationalisierungs-Demo
m.sample_text() Dieser Text wird basierend auf der aktuellen Sprache übersetzt.

Pluralisierung

ICU MessageFormat handles pluralization rules per language.

m.items_count({ count: 0 }) 0 Elemente
m.items_count({ count: 1 }) 1 Elemente
m.items_count({ count: 2 }) 2 Elemente
m.items_count({ count: 5 }) 5 Elemente
m.items_count({ count: 42 }) 42 Elemente

Datums- & Zahlenformatierung

Formatting uses the browser's Intl API, decoupled from the translation locale. A German user in Switzerland gets German text but Swiss number formatting.

Formatiertes Datum 15.01.2025
Formatiertes Datum (long) Mittwoch, 15. Januar 2025
Formatierte Zahl 1.234.567,89
Formatierte Währung (EUR) 1.234,50 €
Formatierte Währung (USD) 1.234,50 $
Formatierter Prozentsatz 85,4 %
Relative Zeit vorgestern

Content Translation (Database)

The tc() helper translates JSON fields from the database, falling back through: current locale → English → first available.

tc(post.title, post.titleI18n, locale) Hallo Welt
tc(post.description, post.descriptionI18n, locale) Dieser Inhalt ist in der Datenbank als JSON gespeichert.

Database Schema Pattern

// EN canonical column + JSONB i18n sibling per non-base locale
name: text('name').notNull(),
nameI18n: jsonb('name_i18n')
  .$type<Partial<Record<'de'|'ru', string>>>()
  .notNull().default(sql`'{}'::jsonb`),
// Render: tc(row.name, row.nameI18n, locale)

Error Codes

Domain code throws stable error codes; adapters resolve them to localized strings via errorMessage(code). Switching locale re-renders without re-submitting.

errorMessage(ErrorCode.AUTH_INVALID) Ungültige Zugangsdaten.
errorMessage(ErrorCode.VALIDATION_REQUIRED) Dieses Feld ist erforderlich.
errorMessage(ErrorCode.RATE_LIMITED) Zu viele Anfragen. Bitte warten Sie einen Moment.
errorMessage(ErrorCode.RESOURCE_NOT_FOUND) Wir konnten nicht finden, wonach Sie suchen.

Typsicherheit

Alle Nachrichtenschlüssel werden zur Kompilierzeit geprüft mit vollständiger IntelliSense-Unterstützung. Fehlende Schlüssel oder falsche Parameter verursachen Build-Fehler, keine Laufzeitfehler.

Compile-time Guarantees

// ✅ Type-safe with autocomplete
m.greeting({ name: 'Alice' });

// ❌ Compile error — missing parameter
m.greeting();

// ❌ Compile error — unknown message key
m.unknownKey();
← Back to Showcases