Skip to main content

Multi-Language (i18n) Implementation

JSONB-based multi-language system supporting 14 languages with dynamic language switching.
Implementation: Phase 3-5 complete. Backend API localization with query parameter-based language selection.

Supported Languages

English

en - English (Required fallback)

Vietnamese

vi - Tiếng Việt

Japanese

ja - 日本語

Chinese

zh - 中文

Korean

ko - 한국어

Thai

th - ภาษาไทย

Indonesian

id - Bahasa Indonesia

French

fr - Français

German

de - Deutsch

Spanish

es - Español

Lao

lo - ພາສາລາວ

Khmer

km - ខ្មែរ

Burmese

my - မြန်မာ

Filipino

fil - Wikang Tagalog

Architecture

Data Storage (Database Layer)

Translatable fields stored as JSONB in PostgreSQL with English as required fallback:

Implementation Stack

Files:
  • backend/src/common/utils/i18n.util.ts - Translation utilities
  • backend/src/common/decorators/language.decorator.ts - Language decorator
  • backend/src/common/interceptors/language.interceptor.ts - Language interceptor
API Query Parameter:

Service & Staff Localization

Services Module

Endpoint Examples


Utility Functions

Core Functions

Creates and validates translated field. Requires English (en) translation.
Extracts localized string from translated field. Falls back to English if language not available.
Localizes specific fields in a single object. Returns new object with localized values.
Localizes specific fields in array of objects. Used for list endpoints.

Additional Utilities


API Response Format

Services Endpoint

name and description are localized strings, not JSONB objects.

Staff Endpoint


Implementation Patterns

Service Method Pattern

All GET endpoints follow this pattern:

Controller Pattern


Frontend Integration

API Client Usage

Response Handling

Frontend receives localized strings directly (no translation needed):

Database Schema


Best Practices

1

Always Include English

Every translatable field must have English (en) as fallback
2

Use Type Safety

Use SupportedLanguage type for language parameters
3

Normalize Input

Use normalizeLanguageCode() before validation
4

Validate Languages

Check with isSupportedLanguage() before using
5

Localize on Response

Apply localization in service methods, not controllers
6

Test Fallbacks

Verify English fallback works for missing translations

Error Handling

The system handles edge cases gracefully:

Project Roadmap

Development timeline

Code Standards

Coding conventions

API Reference

API endpoints

Back to Home

Return to homepage