Configuration options for Translation model instances.

This interface defines the complete configuration structure for individual translation namespace models, including locale settings, resolution strategies, and custom loading mechanisms. Translation models handle the actual key resolution and interpolation for specific functional areas within KOS applications.

Example: Basic Translation Configuration

// Device status translations with English fallback
const statusOptions: TranslationOptions = {
namespace: 'device-status',
currentLocale: 'es',
defaultLocale: 'en',
descriptor: {
'es': {
fallbacks: ['en']
},
'en': {
fallbacks: []
}
},
kosParentId: 'translation-container'
};

const statusTranslation = Translation.instance('status-translations')
.options(statusOptions)
.build();

Example: Custom Bundle Resolution

// API-based translation loading
const apiBundleResolver = async (
namespace: string,
locale: string,
context?: KosContext
): Promise<TranslationResponse> => {
const response = await fetch(`/api/translations/${namespace}/${locale}`);
return await response.json();
};

const apiOptions: TranslationOptions = {
namespace: 'alerts',
currentLocale: 'fr',
defaultLocale: 'en',
descriptor: {
'fr': { fallbacks: ['en'] },
'en': { fallbacks: [] }
},
bundleResolver: apiBundleResolver,
kosParentId: 'translation-container'
};

Example: Multi-Regional Configuration

// Complex fallback chains for regional variations
const regionalOptions: TranslationOptions = {
namespace: 'regional-ui',
currentLocale: 'pt-BR',
defaultLocale: 'en',
descriptor: {
'pt-BR': { fallbacks: ['pt', 'es', 'en'] },
'pt-PT': { fallbacks: ['pt', 'es', 'en'] },
'pt': { fallbacks: ['es', 'en'] },
'es': { fallbacks: ['en'] },
'en': { fallbacks: [] }
},
kosParentId: 'translation-container'
};
interface TranslationOptions {
    namespace: string;
    currentLocale: string;
    defaultLocale: string;
    descriptor: Record<string, LocaleDescriptor>;
    rootUrl?: string;
    resolver?: ((namespace, locale) => string);
    bundleResolver?: ((namespace, locale, context?) => Promise<TranslationResponse>);
}

Hierarchy

  • KosParentAware
    • TranslationOptions

Properties

namespace: string

Translation namespace identifier, typically corresponding to a feature area. Used to organize translations by functional domain and prevent key conflicts.

Example

"device-status"

Example

"user-settings"

Example

"maintenance-scheduler"
currentLocale: string

Current active locale for this translation model. Determines which language variant to load and display.

Example

"en" - English

Example

"es" - Spanish

Example

"pt-BR" - Brazilian Portuguese
defaultLocale: string

Default fallback locale when translations are missing in the current locale. Typically set to the primary application language.

Default

"en"
descriptor: Record<string, LocaleDescriptor>

Locale descriptors defining fallback chains and configuration for each locale. Maps locale codes to their fallback hierarchy and metadata.

rootUrl?: string

Optional base URL for translation file loading. Used with default file-based resolution strategy.

Example

"/assets/locales"

Example

"https://cdn.example.com/translations"
resolver?: ((namespace, locale) => string)

Optional custom path resolver for translation file loading. Overrides default path construction logic.

Type declaration

    • (namespace, locale): string
    • Parameters

      • namespace: string

        Target translation namespace

      • locale: string

        Target locale code

      Returns string

Returns

Full path to translation resource

bundleResolver?: ((namespace, locale, context?) => Promise<TranslationResponse>)

Optional custom bundle resolver for advanced translation loading strategies. Enables loading from APIs, device storage, or custom sources.

Type declaration

    • (namespace, locale, context?): Promise<TranslationResponse>
    • Parameters

      • namespace: string

        Target translation namespace

      • locale: string

        Target locale code

      • Optional context: KosContext

        KOS context for accessing shared data

      Returns Promise<TranslationResponse>

Returns

Promise resolving to translation data