import { tl } from '@mtcute/core'; type Values = T[keyof T]; type SafeGet = T extends Record ? T[K] : never; /** * Literal translated value, represented by (optionally formatted) string */ export type I18nValueLiteral = string | { readonly text: string; readonly entities?: tl.TypeMessageEntity[]; }; /** * Dynamic translated value, represented by a * function resolving to a literal one */ export type I18nValueDynamic = (...args: Args) => I18nValueLiteral; /** * Translated value. Can either be actual value or a function resolving to one */ export type I18nValue = I18nValueLiteral | I18nValueDynamic; /** * Strings dictionary * * Note that `value` key is reserved for internal needs, and cannot be used. */ export interface I18nStrings { [key: string]: I18nValue | I18nStrings; } type NestedKeysDelimited = Values<{ [key in Extract]: T[key] extends I18nValue ? key : `${key}.${T[key] extends infer R ? NestedKeysDelimited : never}`; }>; type GetValueNested = K extends `${infer P}.${infer Q}` ? GetValueNested, Q> : SafeGet; type ExtractParameter = GetValueNested extends (...params: infer R) => I18nValueLiteral ? R : []; /** * Translation "adapter". * * Used to extract language from `Input` object. */ export type MtcuteI18nAdapter = (obj: Input) => string | null | undefined; /** * Translation function. */ export type MtcuteI18nFunction = >(lang: Input | string | null, key: K, ...params: ExtractParameter) => I18nValueLiteral; /** * Wrapper type for i18n object containing strings for a language * other than the primary one. Used to provide type safety. */ export type OtherLanguageWrap = { [key in keyof Strings]?: Strings[key] extends I18nValue ? I18nValue : Strings[key] extends Record ? OtherLanguageWrap : never; }; /** * Wrapper type for i18n object containing strings for a language * other than the primary one. Used to provide type safety. * * Unlike {@link OtherLanguageWrap}, this type requires all strings * from the primary language to be present */ export type OtherLanguageWrapExhaustive = { [key in keyof Strings]: Strings[key] extends I18nValue ? I18nValue : Strings[key] extends Record ? OtherLanguageWrapExhaustive : never; }; export {};