UNPKG

dbl-utils

Version:

Utilities for dbl, adba and others projects

228 lines (227 loc) 6.09 kB
/** * Enable or disable text tracking. * When enabled every translation key requested will be stored. * * @param setTracking - Whether tracking should be enabled * * @example * ```ts * trackingTexts(true); * t('hello'); * trackingTexts(false); * getTexts(); // ['hello'] * ``` */ export declare function trackingTexts(setTracking?: boolean): void; /** * Retrieve the list of tracked texts. * * @returns Array of unique translation keys requested * * @example * ```ts * getTexts(); * ``` */ export declare function getTexts(): string[]; /** * Adds a dictionary to the configuration object. * @param {Object} dictionary - The dictionary to add. * @returns {boolean} True if added correctly, false otherwise. * * @example * ```ts * addDictionary({ es: { hello: 'Hola' } }); * ``` */ export declare const addDictionary: (dictionary: object) => boolean; /** * Adds date formats to the configuration object. * @param {Object} formats - The date formats to add. * @returns {boolean} True if added correctly, false otherwise. * * @example * ```ts * addFormatDate({ es: 'DD/MM/YYYY' }); * ``` */ export declare const addFormatDate: (formats: object) => boolean; /** * Adds time formats to the configuration object. * @param {Object} formats - The time formats to add. * @returns {boolean} True if added correctly, false otherwise. * * @example * ```ts * addFormatTime({ es: 'HH:mm' }); * ``` */ export declare const addFormatTime: (formats: object) => boolean; /** * Adds date-time formats to the configuration object. * @param {Object} formats - The date-time formats to add. * @returns {boolean} True if added correctly, false otherwise. * * @example * ```ts * addFormatDateTime({ es: 'DD/MM HH:mm' }); * ``` */ export declare const addFormatDateTime: (formats: object) => boolean; /** * Adds number formats to the configuration object. * @param {Object} formats - The number formats to add. * @returns {boolean} True if added correctly, false otherwise. * * @example * ```ts * addFormatNumber({ es: { short: { maximumFractionDigits: 1 } } }); * ``` */ export declare const addFormatNumber: (formats: object) => boolean; /** * Adds compact number formats to the configuration object. * @param {Object} formats - The compact number formats to add. * @returns {boolean} True if added correctly, false otherwise. * * @example * ```ts * addFormatNumberCompact({ es: '0a' }); * ``` */ export declare const addFormatNumberCompact: (formats: object) => boolean; /** * Adds currency formats to the configuration object. * @param {Object} formats - The currency formats to add. * @returns {boolean} True if added correctly, false otherwise. * * @example * ```ts * addFormatCurrency({ es: { short: { currency: 'EUR' } } }); * ``` */ export declare const addFormatCurrency: (formats: object) => boolean; /** * Adds tasks to be executed on language change. * @param {Object} tasks - The tasks to add. * @returns {boolean} True if added correctly, false otherwise. * * @example * ```ts * addTasks({ reload: lang => console.log(lang) }); * ``` */ export declare const addTasks: (tasks: Record<string, (lang: string) => void>) => boolean; /** * Removes a specific task. * @param {string} key - The key of the task to remove. * @returns {boolean} True if removed, false otherwise. * * @example * ```ts * removeTask('reload'); * ``` */ export declare const removeTask: (key: string) => boolean; /** * Sets the current language. * @param {string} newLang - The new language to set. * @returns {boolean} True if set correctly, false otherwise. * * @example * ```ts * setLang('es'); * ``` */ export declare const setLang: (newLang: string) => boolean; /** * Gets the current language. * @returns {string} The current language. * * @example * ```ts * const lang = getLang(); * ``` */ export declare const getLang: () => string; /** * Function to translate texts. * @param {string} text - The text to translate. * @param {string} [context] - The context of the text. * @returns {string} The translated text. * * @example * ```ts * addDictionary({ es: { hello: 'Hola' } }); * setLang('es'); * t('hello'); // 'Hola' * ``` */ declare const t: (text: string, context?: string) => string; /** * Formats a date according to the current language and context. * @param {string} [context] - The context of the date. * @returns {string} The formatted date. * * @example * ```ts * formatDate(); * ``` */ export declare const formatDate: (context?: string) => string; /** * Formats a time according to the current language and context. * @param {string} [context] - The context of the time. * @returns {string} The formatted time. * * @example * ```ts * formatTime(); * ``` */ export declare const formatTime: (context?: string) => string; /** * Formats a date-time according to the current language and context. * @param {string} [context] - The context of the date-time. * @returns {string} The formatted date-time. * * @example * ```ts * formatDateTime(); * ``` */ export declare const formatDateTime: (context?: string) => string; /** * Formats a number according to the current language and context. * @param {string} [context] - The context of the number. * @returns {string} The formatted number. * * @example * ```ts * formatNumber(); * ``` */ export declare const formatNumber: (context?: string) => string; /** * Formats a compact number according to the current language and context. * @param {string} [context] - The context of the compact number. * @returns {string} The formatted compact number. * * @example * ```ts * formatNumberCompact(); * ``` */ export declare const formatNumberCompact: (context?: string) => string; /** * Formats a currency according to the current language and context. * @param {string} [context] - The context of the currency. * @returns {string} The formatted currency. * * @example * ```ts * formatCurrency(); * ``` */ export declare const formatCurrency: (context?: string) => string; export default t;