import type { UmbLocalizationConsumer, UmbLocalizationSetBase, UmbLocalizationSetKey } from './localization.manager.js'; import './known-keys.types.generated.js'; import type { UmbController, UmbControllerHost } from '../controller-api/index.js'; /** * Resolves the union of valid keys for a localization set, excluding the metadata fields * declared on `UmbLocalizationSetBase` (`$code`, `$dir`). The `(string & {})` intersection * preserves literal-key autocomplete while still accepting dynamic keys (e.g., * `` `login_greeting${day}` ``). * * If `LocalizationSetType` has an index signature (the legacy `UmbLocalizationSet` shape), * `keyof` returns the index signature's key type and autocomplete falls back to free-form * strings — no narrowing, no breakage. The default generic now points at * `UmbKnownLocalizationSet`, which is the codegen output with literal keys, so callers get * autocomplete out of the box. */ type LocalizationKeyOf = (Exclude & string) | (string & {}); /** * Resolves the argument tuple for a localization key. * * - **Function entries** (e.g., `(name: string) => string`) forward their parameter list so the * call site is checked against the source signature. * - **String entries** stay as `unknown[]` rather than `[]`. The runtime supports `%0%` and * `{0}` placeholder substitution on string values (see `#processTerm`), so passing args to a * string key is intentional, not an error. * - **Dynamic-string escape hatch** (`(string & {})`) falls back to `unknown[]` so consumers * building a key on the fly (e.g., `` `login_greeting${day}` ``) aren't forced to cast. */ type LocalizationArgsOf = K extends keyof T ? T[K] extends (...args: infer U) => string ? U : unknown[] : unknown[]; /** * The UmbLocalizationController enables localization for your element. * @see UmbLocalizeElement * @example * ```ts * import { UmbLocalizationController } from './index.js'; * * \@customElement('my-element') * export class MyElement extends LitElement { * private localize = new UmbLocalizationController(this); * * render() { * return html`

${this.localize.term('general_close')}

`; * } * } * ``` */ export declare class UmbLocalizationController implements UmbController, UmbLocalizationConsumer { #private; readonly controllerAlias: symbol; constructor(host: UmbControllerHost); hostConnected(): void; hostDisconnected(): void; destroy(): void; documentUpdate(): void; keysChanged(changedKeys: Set): void; /** * Gets the host element's directionality as determined by the `dir` attribute. The return value is transformed to * lowercase. * @returns {string} - the directionality. */ dir(): string; /** * Gets the host element's language as determined by the `lang` attribute. The return value is transformed to * lowercase. * @returns {string} - the language code. */ lang(): string; /** * Outputs a translated term. * @param key The localization key to retrieve. Typed as `LocalizationKeyOf` — * literal-key autocomplete from `UmbKnownLocalizationSet` plus a `(string & {})` escape * hatch for dynamic keys. * @param args The arguments to parse for this localization entry. Resolved by * `LocalizationArgsOf`: function-valued entries forward their * parameter list (so `(name: string) => string` requires a `string` here); string-valued * entries accept `unknown[]` for the runtime `%0%` / `{0}` substitution path. * @returns {string} - the translated term as a string. * @example * Retrieving a term without any arguments: * ```ts * this.localize.term('area_term'); * ``` * Retrieving a term with arguments: * ```ts * this.localize.term('general_greeting', 'John'); * ``` */ term>(key: K, ...args: LocalizationArgsOf): string; /** * Returns the localized term for the given key, or the default value if not found. * This method follows the same resolution order as term() (primary → secondary → fallback), * but returns the provided defaultValue instead of the key when no translation is found. * @param key The localization key to retrieve. Typed as `LocalizationKeyOf` — * literal-key autocomplete from `UmbKnownLocalizationSet` plus a `(string & {})` escape * hatch for dynamic keys. * @param defaultValue The value to return if the key is not found in any localization set. * @param args The arguments to parse for this localization entry. Resolved by * `LocalizationArgsOf`: function-valued entries forward their * parameter list; string-valued entries accept `unknown[]` for the runtime `%0%` / `{0}` * substitution path. * @returns {string | null} - the translated term or the default value. * @example * Retrieving a term with fallback: * ```ts * this.localize.termOrDefault('general_close', 'X'); * ``` * Retrieving a term with fallback and arguments: * ```ts * this.localize.termOrDefault('general_greeting', 'Hello!', userName); * ``` * Retrieving a term with null as fallback: * ```ts * this.localize.termOrDefault('general_close', null); * ``` */ termOrDefault, D extends string | null>(key: K, defaultValue: D, ...args: LocalizationArgsOf): string | D; /** * Outputs a localized date in the specified format. * @param {Date} dateToFormat - the date to format. * @param {Intl.DateTimeFormatOptions} options - the options to use when formatting the date. * @returns {string} - the formatted date. */ date(dateToFormat: Date | string, options?: Intl.DateTimeFormatOptions): string; /** * Outputs a localized date with time using short date and medium time format. * @param {Date | string} dateToFormat - the date to format. * @returns {string} - the formatted date and time. */ dateTime(dateToFormat: Date | string): string; /** * Outputs a localized number in the specified format. * @param {number | string} numberToFormat - the number or string to format. * @param {Intl.NumberFormatOptions} options - the options to use when formatting the number. * @returns {string} - the formatted number. */ number(numberToFormat: number | string, options?: Intl.NumberFormatOptions): string; /** * Outputs a localized time in relative format. * @example "in 2 days" * @param {number} value - the value to format. * @param {Intl.RelativeTimeFormatUnit} unit - the unit of time to format. * @param {Intl.RelativeTimeFormatOptions} options - the options to use when formatting the time. * @returns {string} - the formatted time. */ relativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions): string; /** * Outputs a localized compounded time in a duration format. * @example "2 days, 3 hours and 5 minutes" * @param {Date} fromDate - the date to compare from. * @param {Date} toDate - the date to compare to, usually the current date (default: current date). * @param {object} options - the options to use when formatting the time. * @returns {string} - the formatted time, example: "2 days, 3 hours, 5 minutes" */ duration(fromDate: Date | string, toDate?: Date | string, options?: any): string; /** * Outputs a localized list of values in the specified format. * @example "one, two, and three" * @param {Iterable} values - the values to format. * @param {Intl.ListFormatOptions} options - the options to use when formatting the list. * @returns {string} - the formatted list. */ list(values: Iterable, options?: Intl.ListFormatOptions): string; /** * Translates a string containing one or more terms. The terms should be prefixed with a `#` character. * If the term is found in the localization set, it will be replaced with the localized term. * If the term is not found, the original term will be returned. * @param {string | undefined} text The text to translate. * @param {unknown[]} args The arguments to parse for this localization entry. * @returns {string} The translated text. */ string(text: string | undefined, ...args: unknown[]): string; /** * Like {@link string}, but returns a Lit `unsafeHTML` directive with all arguments escaped via {@link escapeHTML}. * Use when the localized value itself contains HTML markup that must be rendered (otherwise prefer {@link string}, which Lit escapes natively). * Pass a `#key` to look up a term, or any string for inline replacement. * @param {string | undefined} text - text to translate (terms prefixed with `#`). * @param {unknown[]} args - arguments to interpolate. Each argument is HTML-escaped before being inserted into the term. * @returns {unknown} a Lit directive result that renders the localized HTML safely inline in a Lit template. * @example * ```ts * html`

${this.localize.htmlString('#defaultdialogs_confirmdelete', userControlledName)}

` * ``` */ htmlString(text: string | undefined, ...args: unknown[]): import("lit-html/directive.js").DirectiveResult; } export {};