@kkdev92/vscode-ext-kit - v4.1.1
    Preparing search index...

    Interface LocalizationService

    Everything an extension needs to show text in the user's language.

    One service rather than a handful of free functions, because every member needs the same fact — the host's display language. Reading it separately in each call site is how a report ends up half in the user's language and half in someone else's, and the mismatch is invisible until it reaches a reader who notices. Here the language is resolved once, so every member agrees.

    Formatting for an explicit locale — a webview, a log file, a bug report meant to be compared against another — is the *For functions in ./format.js, which take the language and need no host at all.

    module.commands.handle(Greet, {
    inject: { l10n: Localization },
    execute: (_context, _args, { l10n }) => l10n.t('Hello, {0}!', name),
    });
    interface LocalizationService {
        language: string;
        date(value: Date, options?: DateFormatOptions): string;
        is(locale: string): boolean;
        number(value: number, options?: NumberFormatOptions): string;
        plural(
            count: number,
            forms: PluralForms,
            extra?: Record<string, string | number>,
        ): string;
        relativeTime(
            value: number,
            unit: RelativeTimeUnit,
            style?: "long" | "short" | "narrow",
        ): string;
        t(message: string, ...args: (string | number | boolean)[]): string;
        t(message: LocalizedMessage): string;
    }
    Index
    language: string

    The host's display language, as a BCP 47 tag ('en', 'ja-JP', ...).

    • Whether the display language matches a locale prefix, so 'ja' covers 'ja' and 'ja-JP' alike.

      This is a lexical prefix check, not locale negotiation or canonicalization; pass normalized tags supplied by the host.

      Parameters

      • locale: string

      Returns boolean

      if (l10n.is('ja')) { ... }
      
    • Picks the plural form the display language calls for.

      Parameters

      • count: number
      • forms: PluralForms
      • Optionalextra: Record<string, string | number>

      Returns string

      l10n.plural(3, { one: '{count} item', other: '{count} items' }); // '3 items'
      
    • Formats a relative time for the display language.

      Parameters

      • value: number
      • unit: RelativeTimeUnit
      • Optionalstyle: "long" | "short" | "narrow"

      Returns string

      l10n.relativeTime(-1, 'day'); // '1 day ago' (en) / '1 日前' (ja)
      
    • Translates a message, filling {0}, {1} from args.

      Bind this service as l10n and the call reads l10n.t('...'), which is the callee pattern @vscode/l10n-dev's string extractor scans for. The shape is the contract: a bare t(...) cannot be found by that tool. For a string the extractor absolutely must see, vscode.l10n.t directly is still the safest option.

      Parameters

      • message: string
      • ...args: (string | number | boolean)[]

      Returns string

      l10n.t('Found {0} files', count);
      
    • Translates a message carrying context for translators.

      Parameters

      Returns string

      l10n.t({ message: 'Found {0} files', args: [count], comment: 'Status bar' });