import type { Locale } from 'date-fns'; import type { clientTranslationKeys } from './clientKeys.js'; import type { enTranslations } from './languages/en.js'; import type { acceptedLanguages } from './utilities/languages.js'; type DateFNSKeys = 'ar' | 'az' | 'bg' | 'bn-BD' | 'bn-IN' | 'ca' | 'cs' | 'da' | 'de' | 'en-US' | 'es' | 'et' | 'fa-IR' | 'fr' | 'he' | 'hr' | 'hu' | 'hy-AM' | 'id' | 'is' | 'it' | 'ja' | 'ko' | 'lt' | 'lv' | 'nb' | 'nl' | 'pl' | 'pt' | 'ro' | 'rs' | 'rs-Latin' | 'ru' | 'sk' | 'sl-SI' | 'sv' | 'ta' | 'th' | 'tr' | 'uk' | 'vi' | 'zh-CN' | 'zh-TW'; export type Language = { dateFNSKey: DateFNSKeys; translations: TDefaultTranslations; }; export type GenericTranslationsObject = { [key: string]: GenericTranslationsObject | string; }; export type GenericLanguages = { [key in AcceptedLanguages]?: GenericTranslationsObject; }; export type AcceptedLanguages = (typeof acceptedLanguages)[number]; export type SupportedLanguages = { [key in AcceptedLanguages]?: Language; }; /** * Type utilities for converting between translation objects ( e.g. general: { createNew: 'Create New' } ) and translations keys ( e.g. general:createNew ) */ export type NestedKeysUnSanitized = T extends object ? { [K in keyof T]-?: K extends string ? T[K] extends object ? `${K}:${NestedKeysUnSanitized}` | null : `${K}` : never; }[keyof T] : ''; export type StripCountVariants = TKey extends `${infer Base}_many` | `${infer Base}_one` | `${infer Base}_other` ? Base : TKey; export type NestedKeysStripped = T extends object ? { [K in keyof T]-?: K extends string ? T[K] extends object ? `${K}:${NestedKeysStripped}` : `${StripCountVariants}` : never; }[keyof T] : ''; export type ReconstructObjectFromTranslationKeys = TPath extends `${infer First}:${infer Rest}` ? { [K in First]: ReconstructObjectFromTranslationKeys; } : { [K in TPath]: TValue; }; /** * Default nested translations object */ export type DefaultTranslationsObject = typeof enTranslations; /** * All translation keys unSanitized. E.g. 'general:aboutToDeleteCount_many' */ export type DefaultTranslationKeysUnSanitized = NestedKeysUnSanitized; /** * All translation keys sanitized. E.g. 'general:aboutToDeleteCount' */ export type DefaultTranslationKeys = NestedKeysStripped; export type ClientTranslationKeys = TExtraProps; export type ClientTranslationsObject = GenericTranslationsObject; export type TFunction = (key: TTranslationKeys, options?: Record) => string; export type I18n = { dateFNS: Locale; /** Corresponding dateFNS key */ dateFNSKey: DateFNSKeys; /** The fallback language */ fallbackLanguage: string; /** The language of the request */ language: string; /** Translate function */ t: TFunction; translations: Language['translations']; }; export type I18nOptions = { fallbackLanguage?: AcceptedLanguages; supportedLanguages?: SupportedLanguages; translations?: Partial<{ [key in AcceptedLanguages]?: Language['translations']; }>; }; export type InitTFunction = (args: { config: I18nOptions; language?: string; translations: Language['translations']; }) => { t: TFunction; translations: Language['translations']; }; export type InitI18n = ((args: { config: I18nOptions; context: 'api'; language: AcceptedLanguages; }) => Promise) | ((args: { config: I18nOptions; context: 'client'; language: AcceptedLanguages; }) => Promise>); export type LanguagePreference = { language: AcceptedLanguages; quality?: number; }; export type I18nClient = I18n; export type I18nServer = I18n; export {}; //# sourceMappingURL=types.d.ts.map