TranslationContainer - Multi-namespace translation management with automatic locale switching.

The TranslationContainer model serves as the central orchestrator for internationalization in KOS applications. It manages multiple translation namespaces, handles global locale switching, and provides namespace resolution with fallback chains. This container enables building sophisticated multi-language interfaces that adapt automatically to user language preferences across all application features.

Key Features

  • Multi-Namespace Management - Organize translations by feature areas (dashboard, alerts, settings)
  • Global Locale Control - Centralized locale switching affects all contained translation models
  • Automatic Discovery - Dynamic namespace loading and registration as features request translations
  • Fallback Resolution - Sophisticated locale fallback chains for graceful degradation
  • Custom Resolvers - Flexible translation loading strategies for different deployment scenarios
  • Reload Capability - Dynamic translation updates without application restart
  • Default Namespace - Optional primary namespace for application-wide common translations

Namespace Organization

Translation namespaces organize translations by functional areas:

  • Feature-Based: dashboard, device-config, maintenance, alerts
  • Component-Based: forms, modals, navigation, status-displays
  • Common: common, shared, ui-elements for cross-cutting concerns

Locale Management Architecture

The container manages locale switching across all child translation models:

  1. Centralized Control: Single point for locale changes
  2. Automatic Propagation: All child models receive locale updates
  3. Reactive Loading: Translation files loaded automatically on locale switch
  4. Fallback Coordination: Container coordinates fallback chains across namespaces

Common Use Cases

  • Application Initialization - Bootstrap internationalization system with locale descriptors
  • User Language Switching - Provide language selector that updates entire application
  • Feature Translation Loading - Dynamic namespace registration as features are accessed
  • Multi-Tenant Systems - Different translation sets for different deployments
  • Development Workflows - Hot-reload translations during development
  • Global Device Interfaces - Centralized management for device control applications

Example: Basic Usage

const translationContainer = TranslationContainer.instance('app-translations')
.options({
lang: 'es',
defaultNamespace: 'common',
descriptor: {
namespaces: {
'common': {
basePath: '/assets/locales',
locales: {
'en': { file: 'en/common.json', defaultLocale: 'en' },
'es': { file: 'es/common.json', defaultLocale: 'en' }
}
}
}
}
})
.build();

// Access translations and switch language
const commonTranslations = translationContainer.getModel('common');
translationContainer.currentLocale = 'fr';

Use Declared Type

See

  • TranslationContainerOptions - Configuration options for TranslationContainer instances
  • TranslationModel - Individual translation namespace model
  • useKosTranslation - React hook for accessing container translations
  • useKosTranslationContext - React hook for container-level operations
interface TranslationContainerModel {
    id: string;
    lang: string;
    descriptor: Localization;
}

Properties

Properties

id: string

Unique identifier for the container model instance

lang: string

Currently active locale for all managed translation namespaces

descriptor: Localization

Localization descriptor defining namespace configuration and locale mappings