@sovereignbase/utils
    Preparing search index...

    Class LanguageBroker<SupportedLanguages>

    Stores the active language and notifies consumers when it changes.

    Each call to set updates the stored BCP 47 language tag, invokes the optional change callback, and dispatches a typed change event.

    Requires the standard EventTarget and CustomEvent globals.

    const languages = new LanguageBroker(
    'en-US',
    ['en-US', 'fi-FI'],
    (language) => {
    document.documentElement.lang = language
    }
    )

    languages.addEventListener('change', (event) => {
    console.log(event.detail)
    })

    languages.set('fi-FI')

    Type Parameters

    Index
    • Checks whether a string is supported by this broker.

      A successful check narrows the string to the inferred supported language union.

      Parameters

      • language: string

        The string to check.

      Returns language is SupportedLanguages[number]

    • Updates the active language and notifies all consumers.

      Languages outside the supported list are ignored at runtime.

      Parameters

      • language: SupportedLanguages[number]

        The new active language from the supported language list.

      Returns void