import type { TLocalisationSource } from "../../../types/localisation.d.mts"; type TLocaleSource = TLocalisationSource; type TLocaleDictionary = TLocaleSource[string]; type TLocaleValue = TLocaleDictionary[string][number]; type TFlatLocaleSource = Record; /** * Тип для одного языка в формате i18next resources. * Структура: { [ns: string]: { [key: string]: TLocaleValue } } */ type TLanguageResources = Record>; /** * Полный формат resources для i18next. * Структура: { [lang: string]: { [type: string]: TLanguageResources } } */ type TResources = Record>; /** * Проверяет, является ли значение обычным объектом (не null, не массив) * @returns {boolean} */ declare const isRecord: (value: unknown) => value is Record; /** * Проверяет, является ли значение допустимым значением локали (строка или функция) * @returns {boolean} */ declare const isLocaleValue: (value: unknown) => value is TLocaleValue; /** * Получает плоский объект ресурсов для указанного namespace. * Преобразует вложенную структуру { name: { key: value } } в плоскую { "name.key": value }. * * @param values{TLocaleSource} исходные данные локализации * @param ns{string} пространство имён * @returns {TFlatLocaleSource} плоский объект с ключами вида "name.key" * @example * const source = { * translation: { * forms: { invalidInput: ["Ошибка", "Error"] }, * buttons: { submit: ["Отправить", "Submit"] } * } * }; * getFlatResourceValues(source, "translation"); * // { "forms.invalidInput": ["Ошибка", "Error"], "buttons.submit": ["Отправить", "Submit"] } */ declare const getFlatResourceValues: (values?: TLocaleSource, ns?: string) => TFlatLocaleSource; /** * Получает данные локализации из объекта и преобразует их в формат i18next resources. * * @param data{TLocaleSource} объект с локалями в формате { ns: { key: [lang1Value, lang2Value, ...] } } * @param type{string} тип ресурса (обычно "translation") * @param langKeys{string[]} массив кодов языков * @returns {TResources} объект ресурсов в формате i18next * @example * const data = { * translation: { * greeting: ["Привет", "Hello"], * farewell: ["Пока", "Bye"] * } * }; * getResourcesFromObj({ data, langKeys: ["ru", "en"] }); * // { ru: { translation: { translation: { greeting: "Привет", farewell: "Пока" } } }, ... } */ declare const getResourcesFromObj: ({ data, type, langKeys, }: { data?: TLocaleSource; type?: string; langKeys?: string[]; }) => TResources; /** * Получает пользовательские атрибуты в виде объекта с одним уровнем вложенности. * Преобразует плоский объект с ключами-путями в обычный вложенный объект. * * @param obj{Record} плоский объект с ключами-путями (например, { "style.color": "red" }) * @returns {Record} вложенный объект (например, { style: { color: "red" } }) * @example * getUserAttrs({ "style.color": "red", "style.fontSize": 16 }); * // { style: { color: "red", fontSize: 16 } } */ declare const getUserAttrs: (obj: Record) => Record; /** * Преобразует TLanguageResources в плоский объект с составными ключами. * Например, { new: { dynamic: "value" } } преобразуется в * { "new.dynamic": "value" }. * @returns {TFlatLocaleSource} */ declare const getFlattenLanguageResources: (resources: TLanguageResources) => TFlatLocaleSource; export type { TFlatLocaleSource, TLanguageResources, TLocaleDictionary, TLocaleSource, TLocaleValue, TResources, }; export { getFlatResourceValues, getFlattenLanguageResources, getResourcesFromObj, getUserAttrs, isLocaleValue, isRecord, };