UNPKG

generaltranslation

Version:

A language toolkit for AI developers

83 lines (77 loc) 2.5 kB
type VariableType = 'v' | 'n' | 'd' | 'c'; /** * Variables are used to store the variable name and type. */ type Variable = { k: string; i?: number; v?: VariableType; }; /** * Map of data-_gt properties to their corresponding React props */ declare const HTML_CONTENT_PROPS: { readonly pl: "placeholder"; readonly ti: "title"; readonly alt: "alt"; readonly arl: "aria-label"; readonly arb: "aria-labelledby"; readonly ard: "aria-describedby"; }; type HtmlContentPropKeysRecord = Partial<Record<keyof typeof HTML_CONTENT_PROPS, string>>; /** * GTProp is an internal property used to contain data for translating and rendering elements. * note, transformations are only read on the server side if they are 'plural' or 'branch' */ type GTProp = { b?: Record<string, JsxChildren>; t?: 'p' | 'b'; } & HtmlContentPropKeysRecord; type JsxElement = { t?: string; i?: number; d?: GTProp; c?: JsxChildren; }; type JsxChild = string | JsxElement | Variable; /** * The format of the content */ type DataFormat = 'JSX' | 'ICU' | 'I18NEXT'; /** * A content type representing JSX elements */ type JsxChildren = JsxChild | JsxChild[]; type HashMetadata = { context?: string; id?: string; maxChars?: number; dataFormat: DataFormat; }; /** * Calculates a unique hash for a given string using sha256. * * First 16 characters of hash, hex encoded. * * @param {string} string - The string to be hashed. * @returns {string} - The resulting hash as a hexadecimal string. */ declare function hashString(string: string): string; /** * Calculates a unique ID for the given children objects by hashing their sanitized JSON string representation. * * @param {any} childrenAsObjects - The children objects to be hashed. * @param {string} context - The context for the children * @param {string} id - The id for the JSX Children object * @param {number} maxChars - The maxChars for the JSX Children object * @param {string} dataFormat - The data format of the sources * @param {function} hashFunction custom hash function * @returns {string} - The unique has of the children. */ declare function hashSource({ source, context, id, maxChars, dataFormat, }: { source: JsxChildren | string; } & HashMetadata, hashFunction?: (string: string) => string): string; declare function hashTemplate(template: { [key: string]: string; }, hashFunction?: typeof hashString): string; export { hashSource, hashString, hashTemplate };