Logos DX
    Preparing search index...

    Class LocaleManager<Locale, Code>

    Type-safe locale manager with async loading, namespace scoping, ICU-lite pluralization, and Intl formatting.

    WHY: Centralizes all i18n concerns — translation lookup, locale switching, lazy-loaded locales, and number/date formatting — behind a single event-driven API.

    const i18n = new LocaleManager<AppLocale, 'en' | 'es'>({
    current: 'en',
    fallback: 'en',
    locales: { en: { code: 'en', text: 'English', labels: english } }
    });

    // Register a lazy-loaded locale
    i18n.register('es', { text: 'Español', loader: () => import('./es.json') });

    // Namespace scoping for feature modules
    const authT = i18n.ns('auth');
    authT.t('login.title'); // resolves 'auth.login.title'

    // Intl formatting follows the current locale automatically
    i18n.intl.number(1499.99); // "1,499.99"
    i18n.intl.date(new Date()); // "2/18/2026"
    i18n.intl.relative(-3, 'day'); // "3 days ago"

    // Async locale switch — emits 'loading' then 'change' events
    const unsub = i18n.on('change', (e) => console.log(e.code));
    await i18n.changeTo('es');
    unsub(); // cleanup

    Type Parameters

    Index

    Constructors

    Properties

    current: Code
    fallback: Code
    t: <K extends string>(key: K, values?: LocaleManager.LocaleFormatArgs) => string

    Returns a label with replaced variables

    const theLang = {
    my: { nested: {
    key: '{0}, I like bacon. {1}, I like eggs.'
    key2: '{first}, I like steak. {second}, I like rice.'
    }}
    }

    t('my.nested.key', ['Yes', 'No']);
    // > 'Yes, I like bacon. No, I like eggs.'

    t('my.nested.key2', { first: 'Ofcourse', second: 'Obviously' });
    // > 'Ofcourse, I like steak. Obviously, I like rice.'

    Accessors

    Methods