Skip to main content

sonamu.config.ts Configuration

Enable the i18n option in sonamu.config.ts:

Directory Structure

When i18n is enabled, the api/src/i18n/ directory is required:

Creating Dictionary Files

defaultLocale Dictionary (ko.ts)

Recommended key naming pattern: Using namespace patterns like "domain.item" helps organize keys systematically and makes IDE autocomplete more convenient. - "common.*" - Common UI - "error.*" - Error messages - "validation.*" - Validation messages - "entity.*" - Entity related

Other Locale Dictionary (en.ts)

defineLocale is exported from sd.generated.ts and provides type checking based on the keys from defaultLocale.

Locale Configuration

Frontend (Client)

sd.generated.ts includes setLocale and getCurrentLocale functions for client-side locale management:
The axios interceptor in sonamu.shared.ts automatically adds the Accept-Language header to all API requests:
After calling setLocale("en"), all subsequent API requests will include the Accept-Language: en header.

Backend (Server)

To set the locale per request, configure the Context in middleware:
When the client calls setLocale(), the axios interceptor automatically sends the Accept-Language header, and the server’s locale middleware reads it so that SD() calls return translations in the correct language. Client-server locale synchronization works without any additional configuration.

Verifying Initialization

After completing the setup, run pnpm sync to verify that sd.generated.ts is generated:
The generated sd.generated.ts includes:
  • Labels extracted from Entity (entityLabels)
  • SD() function
  • localizedColumn() function
  • defineLocale() function

Using the SD Function

Writing and using dictionaries

Entity Labels

Auto-extracted labels