VOOZH about

URL: https://deepwiki.com/mathsgod/light/8.4-internationalization

⇱ Internationalization | mathsgod/light | DeepWiki


Loading...
Last indexed: 31 January 2026 (cf9511)
Menu

Internationalization

Purpose and Scope

This document describes the internationalization (i18n) system in the Light framework, which provides multi-language support through database-backed translations and localized content. The system supports user-specific language preferences and delivers translations through the GraphQL API.

For user management and authentication, see Authentication and Authorization. For system configuration, see System Configuration.


Architecture Overview

The internationalization system consists of three primary components: the Translate model for storing key-value translation pairs, the SystemValue model for storing localized system values with status flags, and user language preferences stored in the User model. All translation data is retrieved dynamically through the GraphQL API based on the authenticated user's language preference.

Diagram: Internationalization Data Model


Sources: db.json1-676


Database Schema

Translate Table

The Translate table stores translation key-value pairs for each supported language. Each translation entry consists of a key (name) and its translated value (value) for a specific language.

ColumnTypeDescription
translate_idint (PK, auto_increment)Unique identifier for translation entry
languagevarchar(5)Language code (e.g., "en", "zh-hk")
namevarchar(255)Translation key identifier
valuevarchar(255)Translated text content

The table has indexes on language, name, action, and module columns for efficient querying. The language and name combination allows looking up specific translations quickly.

Sources: db.json550-605

SystemValue Table

The SystemValue table stores localized system values that can be enabled or disabled through a status flag. This is distinct from the Translate table as it supports longer text content and status management.

ColumnTypeDescription
systemvalue_idint (PK, auto_increment)Unique identifier for system value
namevarchar(64)Value identifier/key
valuetextLocalized content (supports longer text)
statusint (default: 0)Active/inactive flag
languagevarchar(5)Language code

The table has indexes on both language and name columns for efficient filtering and retrieval.

Sources: db.json500-549

User Language Preference

Each user's language preference is stored in the User table's language column, which accepts a 2-5 character language code (e.g., "en", "zh-hk"). This preference determines which translations are automatically loaded for that user.

Sources: db.json64-68


Translation Retrieval Flow

Diagram: Translation Loading Process


Sources: src/Type/App.php143-148

The getI18nMessages method retrieves all translations for the authenticated user's preferred language. The method uses the #[InjectUser] annotation to access the current user context, extracts their language preference (defaulting to "en" if not set), and queries the Translate model for all matching records.

Sources: src/Type/App.php143-148


GraphQL API Methods

getI18nMessages

Returns all translations for the current authenticated user's language preference. This is the primary method used by client applications to load localized text.

Method Signature:


Implementation Details:

  • Requires authentication (#[Logged] annotation)
  • Extracts language from user object: $user->language ?? 'en'
  • Queries Translate model: Translate::Query(["language" => $language])->toArray()
  • Returns array of Light\Model\Translate objects

Sources: src/Type/App.php138-148

getTranslates

Returns all translation records across all languages. This method is typically used for administrative purposes to manage translations.

Method Signature:


Implementation Details:

  • Requires authentication
  • Returns all records from Translate table without filtering
  • Returns array of Light\Model\Translate objects

Sources: src/Type/App.php127-135

getLanguages

Returns the list of supported languages in the system. Currently returns a hardcoded list that can be extended.

Method Signature:


Implementation Details:

  • No authentication required
  • Returns hardcoded array of language options:
    • ["name" => "English", "value" => "en"]
    • ["name" => "中文", "value" => "zh-hk"]

Sources: src/Type/App.php151-158

listSystemValue

Queries the SystemValue table with optional filters and sorting. Requires the systemvalue.list permission.

Method Signature:


Implementation Details:

  • Requires authentication and systemvalue.list permission
  • Accepts filters (e.g., ["language" => "en"]) and sort parameters
  • Returns Light\Db\Query object for pagination support

Sources: src/Type/App.php500-510


Supported Languages

The system currently supports two languages by default:

Language CodeDisplay Name
enEnglish
zh-hk中文 (Traditional Chinese - Hong Kong)

The language list is defined in the getLanguages method and can be extended by modifying the return array. The language column in both Translate and SystemValue tables uses varchar(5) to accommodate standard language codes including regional variants (e.g., "en-US", "zh-CN").

Sources: src/Type/App.php151-158 db.json527-530 db.json561-564


Translation vs SystemValue

Diagram: Model Comparison


Sources: db.json550-605 db.json500-549

Key Differences

FeatureTranslateSystemValue
Value Lengthvarchar(255) - short texttext - long content
Status ManagementNo status fieldHas status flag (active/inactive)
Primary Use CaseUI labels, messages, short stringsLonger localized content, system values
Name Lengthvarchar(255) - longer keysvarchar(64) - shorter identifiers
Additional Indexesaction, module columns (deprecated)Only name and language

The Translate model is optimized for storing UI strings and labels, while SystemValue is designed for longer localized content that may need to be enabled or disabled dynamically through the status flag.

Sources: db.json550-605 db.json500-549


Usage Patterns

Client-Side Translation Loading

When a client application initializes, it typically follows this pattern:

  1. User authenticates and receives JWT token
  2. Client queries getI18nMessages with authenticated request
  3. Framework injects current user via #[InjectUser] annotation
  4. System reads user.language field (defaults to "en")
  5. Query returns all translations for that language
  6. Client caches translations in memory for UI rendering

Sources: src/Type/App.php143-148

Translation Key Naming

The name column in the Translate table serves as the translation key. Common patterns include:

  • Dot notation: "user.login.button", "dashboard.title"
  • Module prefixing: "auth.password.reset", "file.upload.error"
  • Action-based: "save", "cancel", "delete.confirm"

The name column supports up to 255 characters, allowing for descriptive, hierarchical key structures.

Sources: db.json566-569

SystemValue for Dynamic Content

SystemValue entries are suitable for:

  • Terms of service text in multiple languages
  • Help documentation snippets
  • Email templates with localization
  • Configuration values that vary by language

The status field allows administrators to enable/disable specific values without deleting them, useful for A/B testing or gradual rollout of new translations.

Sources: db.json500-549


Model Classes

Both Translate and SystemValue are referenced as model imports in the GraphQL root type and extend the base Light\Model class, providing automatic audit trails and GraphQL type mapping.

Light\Model\Translate - Translation key-value pairs
Light\Model\SystemValue - Localized system values with status

These models are automatically exposed as GraphQL types through GraphQLite's annotation system, allowing them to be queried and mutated through the GraphQL API.

Sources: src/Type/App.php17 src/Type/App.php16


API Integration Summary

Diagram: GraphQL Query Methods


Sources: src/Type/App.php127-158 src/Type/App.php500-510