sonamu.config.ts Configuration
Enable the i18n option insonamu.config.ts:
Directory Structure
When i18n is enabled, theapi/src/i18n/ directory is required:
Creating Dictionary Files
defaultLocale Dictionary (ko.ts)
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:
sonamu.shared.ts automatically adds the Accept-Language header to all API requests:
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, runpnpm sync to verify that sd.generated.ts is generated:
sd.generated.ts includes:
- Labels extracted from Entity (
entityLabels) SD()functionlocalizedColumn()functiondefineLocale()function
Using the SD Function
Writing and using dictionaries
Entity Labels
Auto-extracted labels