Documentation
    Preparing search index...

    Class Translator

    A standard, framework-agnostic translation manager and dictionary resolver. Handles language registration and scoped key extraction with safety fallbacks.

    Index

    Constructors

    • Initializes the translator utility.

      Parameters

      • defaultLang: string = 'en'

        The default language code (e.g. 'en', 'fr') to fallback to if a key is missing.

      Returns Translator

    Properties

    defaultLang: string
    dictionaries: Record<string, CoreDictionary> = {}

    Methods

    • A helper method to perform recursive deep-merging of two dictionary objects.

      Parameters

      • target: any

        The base target object.

      • source: any

        The source object containing updates to merge.

      Returns any

      The deep-merged dictionary object.

    • Dynamically extends and merges existing translation dictionaries. This allows consuming applications to register their specific UI translations at runtime.

      Parameters

      • dicts: Record<string, Record<string, any>>

        A record mapping language keys (e.g. 'en', 'fr') to custom dictionaries.

      Returns void

    • Dynamically extends and merges an existing dictionary for a given language. This allows consuming applications to register their specific UI translations at runtime.

      Parameters

      • lang: string

        The language key code (e.g. 'en', 'fr').

      • customDict: Record<string, any>

        The custom dictionary object containing terms to merge.

      Returns void

    • Returns a Proxy object representing a callable translation shortcut function t.

      Parameters

      • Optionallang: string

        Optional default language code override for this proxy instance.

      Returns any

      A callable and chainable translation Proxy.

      const t = translator.getProxy('en')
      t('app.title') // -> "Core App"
      t.fr('app.title') // -> "Application Core"
    • Registers one or multiple translation language dictionaries.

      Parameters

      • dicts: Record<string, CoreDictionary>

        A record mapping language keys (e.g. 'en', 'fr') to dictionaries.

      Returns void

    • Registers a specific translation language dictionary.

      Parameters

      • lang: string

        The language key code (e.g. 'en', 'fr').

      • dict: CoreDictionary

        The fully conforming Quatrain dictionary instance.

      Returns void

    • Translates a specific text label key inside a given dictionary scope. Supports both standard (scope, key) calls and dotted key path (e.g. "backends.title") notation.

      Parameters

      • scope: string

        The dictionary scope key (e.g. 'table') or a dotted key path (e.g. 'app.title').

      • OptionalkeyOrLang: string

        The specific term key inside the selected scope, or the language code if scope is a dotted key.

      • Optionallang: string

        The target language code to extract from (falls back to default language).

      Returns string

      The localized translation string, or the raw key string if no match was found.