/** * @interface I18nTranslations * Represents a dictionary for internationalization (i18n) strings. * * This interface defines a structure for storing localized strings * for different locales. Each locale can have multiple keys, each * associated with a string or another dictionary for nested translations. * * @example * const translations: I18nTranslations = { * en: { * greeting: "Hello", * farewell: "Goodbye", * nested: { * example: "This is a nested translation.", * } * }, * es: { * greeting: "Hola", * farewell: "Adiós" * } * }; */ import { Dictionary } from '../types'; export type I18nTranslations = { [Locale in string]: Dictionary; }; /** * A formatter function for internationalization (i18n) strings. * * This type defines a function that takes a string value and optional * parameters to format the string according to specific rules or * requirements. The formatted string is then returned. * * @param {string} value - The string value to format. * @param {Record} [params] - Optional parameters to customize the formatting. * @returns {string} The formatted string. * * @example * const formatter: I18nFormatter = (value, params) => { * return value.replace(/{(\w+)}/g, (_, key) => params[key] || ''); * }; * * const greeting = formatter("Hello, {name}!", { name: "John" }); // "Hello, John!" */ export type I18nFormatter = (value: string, params?: Dictionary) => string; /** * Type defining the scope of a translation. * Can be a dot-separated string or an array of keys. */ export type I18nScope = string | string[]; /** * Options for translation. */ export interface I18nTranslateOptions extends Dictionary { /** * Locale to use for this translation. */ locale?: string; /** * Default value if translation is missing. */ defaultValue?: string; /** * Count for pluralization. */ count?: number; } /** * Type defining a namespace resolver function. * * This type defines a function that takes a locale string and returns a promise * that resolves to a dictionary of translations for that locale. The resolver * is used to load translations dynamically when a namespace is requested. * * @param {string} locale - The locale code (e.g., "en"). * @returns {Promise} A promise that resolves to a dictionary of translations. * * @example * const resolver: I18nNamespaceResolver = async (locale) => { * const response = await fetch(`/translations/${locale}.json`); * return response.json(); * }; */ export type I18nNamespaceResolver = (locale: string) => Promise; /** * Interface defining a map of namespace resolvers. * * This interface extends the Record type to define a map of namespace resolvers, * where each key is a string (the namespace name) and each value is an * I18nNamespaceResolver function. * * @example * const resolvers: I18nNamespaceResolvers = { * 'common': (locale) => import('./locales/common'), * 'auth': (locale) => import('./locales/auth'), * }; */ export interface I18nNamespaceResolvers extends Record { }