import type { ElementType } from 'react'; import type { Dictionary } from '../localization/locales'; /** A localization dictionary key */ type Token = keyof Dictionary; /** A dynamic argument that can be used in a localized string */ type DynamicArg = string | number; /** A record of dynamic arguments for a specific key in the localization dictionary */ type ArgsRecord = Record, DynamicArg>; /** The dynamic arguments in a localized string */ type DynamicArgs = // eslint-disable-next-line @typescript-eslint/no-unused-vars LocalizedString extends `${infer _Pre}{${infer Var}}${infer Rest}` ? Var | DynamicArgs : never; /** The arguments for retrieving a localized message */ export type GetMessageArgs = DynamicArgs extends never ? [T] : [T, ArgsRecord]; /** Basic props for all calls of the I18n component */ type I18nBaseProps = { token: T; as?: ElementType }; /** The props for the localization component */ export type I18nProps = DynamicArgs extends never ? I18nBaseProps : I18nBaseProps & { args: ArgsRecord }; /** The dictionary of localized strings */ export type LocalizerDictionary = Dictionary; /** A localization dictionary key */ export type LocalizerToken = keyof LocalizerDictionary;