Setu-TS
    Preparing search index...

    Interface ILocalizer

    Localization contract — looks up and formats messages for one locale.

    Registered under CAPABILITIES.LOCALIZATION ('localization'), bound to the application's default locale. A request-bound view comes from ILocalizer.forLocale with the request's resolved IRequest.locale, which is what the localization plugin's localizerFor(ctx) does.

    Formatting substitutes text and escapes NOTHING: escaping belongs to the runtime that renders the result (the JSX runtime, the html tagged template), exactly as for IViewEngine.render.

    import { CAPABILITIES } from '@setu-ts/common';

    const localizer = ctx.services.get<ILocalizer>(CAPABILITIES.LOCALIZATION);
    const greeting = localizer.forLocale('de').t('greeting', { name: 'Ada' });

    0.9.0

    interface ILocalizer {
        locale: string;
        locales: readonly string[];
        forLocale(tag: string): ILocalizer;
        t(key: string, values?: Readonly<Record<string, unknown>>): string;
    }
    Index
    locale: string

    The BCP 47 tag this localizer formats in.

    locales: readonly string[]

    Every supported tag, the default first.

    • Returns a localizer bound to another SUPPORTED locale.

      Callers pass configuration (a resolved request locale, a user's stored preference already matched against the supported set), never raw user input, so an unsupported tag is a programming error and throws.

      Parameters

      Returns ILocalizer

      A localizer bound to tag

      If tag is not a supported locale

    • Looks up key in this localizer's locale and formats it with values.

      A key absent from every catalogue answers the key itself (and is logged once), unless the implementation was configured to throw — a request never fails over a translation gap by default.

      Parameters

      • key: string

        The message key

      • Optionalvalues: Readonly<Record<string, unknown>>

        Placeholder values; a plural message requires a finite numeric count

      Returns string

      The formatted text