@messageformat/fluent
Version:
Conversion & compatibility tools for using Fluent with MessageFormat 2
36 lines (35 loc) • 1.42 kB
TypeScript
import type { MessageExpressionPart, MessagePart } from 'messageformat';
import type { MessageFunctionContext, MessageValue } from 'messageformat/functions';
import type { FluentMessageResource } from './index.ts';
/**
* The resolved value of a Fluent message or term reference.
*
* See {@link getMessageFunction}.
*/
export interface MessageReferenceValue extends MessageValue<'fluent-message'> {
readonly type: 'fluent-message';
readonly source: string;
readonly dir: 'ltr' | 'rtl' | 'auto';
selectKey(keys: Set<string>): string | null;
toParts(): [MessageReferencePart];
toString(): string;
valueOf(): string;
}
/**
* The formatted part for a {@link MessageReferenceValue}.
*/
export interface MessageReferencePart extends MessageExpressionPart<'fluent-message'> {
type: 'fluent-message';
dir?: 'ltr' | 'rtl';
parts: MessagePart<string>[];
}
/**
* Build a custom function for Fluent message and term references.
*
* By default, {@link fluentToResource} uses this with the id `fluent:message`.
*
* @param res - A Map of {@link MessageFormat} instances,
* one for each referrable message and term.
* This Map may be passed in as initially empty, and later filled out by the caller.
*/
export declare const getMessageFunction: (res: FluentMessageResource) => (ctx: MessageFunctionContext, options: Record<string, unknown>, input?: unknown) => MessageReferenceValue;