/** * LOCALISED TRANSLATIONS (i18n) =============================================== * ============================================================================= */ /** * Prepare definitions for localisation, so they can be accessed via .name property * without needing to specify the language code explicitly. * * @example: * localise(LANGUAGE) * console.log(LANGUAGE.ENGLISH.name) * >>> English * * @param {Object|Object|Object[]} DEFINITION - key/value pairs of variable name with its _ value * Multiple definitions can be nested unlimited times inside a single object. */ export function localise(DEFINITION: Object | Object | Object[]): void; /** * Prepare translations for localisation by mutation, so they can be accessed directly via .TEXT property * @Note: can be applied repeatedly to add new translations or languages after requests from API * * @example: * translate({ * SEARCH: { // use this for key `Search`.replace(/[^a-zA-Z\d]/g, '_').toUpperCase() * [l.ENGLISH]: `Search`, * [l.RUSSIAN]: `Поиск`, * } * }) * log(_.SEARCH) * # if active language is English * >>> 'Search' * # if active language is Russian * >>> 'Поиск' * * Add language: * _.SEARCH = { * ..., // previous definitions * [l.CHINESE]: '搜索', // language addition * } * log(_.SEARCH) * # if active language is Chinese * >>> 搜索 * * @param {Object} TRANSLATION - key/value pairs of variable name with its localised (translated) values * @returns {Object} translations - with all definitions as javascript getters returning currently active language, * (falls back to English if definition not found for active language, or empty string). */ export function translate(TRANSLATION: Object): Object; export namespace translate { const instance: { [p: string]: string; }; const queriedById: {}; } /** * Convert single/multiple Definition values into localised human-readable String(s) * * @param {String|Number|Array} values - definition's underscore value/s * @param {Object} definitionByValue - example: definitionByValue(LANGUAGE) * @param {*} [output] - one of types (i.e. String, Array, etc.) * @returns {String|Array} string/s - for human consumption */ export function valueToName(values: string | number | any[], definitionByValue: Object, output?: any): string | Array; /** * Localised String Object (can be extended by adding new terms or languages) * @note: follow the example to ensure only one instance of translation exists. * @example: * import { _, l, translate } from '@webframer/js' * * // Add or update localised term(s) * translate({ * NEW_PHRASE: { * [l.ENGLISH]: 'New Phrase', * }, * }) * * // Usage: * log(_.NEW_PHRASE) * >>> 'New Phrase' * * // Add or update localised term(s) * translate({ * NEW_PHRASE: { * [l.RUSSIAN]: 'Новая Фраза', * }, * MORE_PHRASES: { * [l.ENGLISH]: 'More Phrases', * }, * }) * * // Existing translations remain * log(_.NEW_PHRASE) * >>> 'New Phrase' * * // Set the current language. * Current.LANGUAGE = LANGUAGE.RUSSIAN * log(_.NEW_PHRASE) * >>> 'Новая Фраза' * * @type {{[p: string]: string}} object that returns localised 'Untranslated' string if no translation found */ export const _: { [p: string]: string; };