import type { LocaleJson, LocaleFields, LocaleStore, AppStaticJson, Fields } from './types'; /** * @description * Provides APIs to create,update and lookup the localization store which is a map of field values. */ declare class LocaleUtils { #private; GENERIC_BUNDLE_KEY: string; FIELD_LABELS_BUNDLE_KEY: string; GENERIC_BUNDLE_KEY_LP: string; MESSAGE_BUNDLE_KEY: string; BASE_CLASS: string; DATA_PAGE_LOCALECONTEXT: string; localeStore: LocaleStore; private timezone?; private availableLangPacks?; constructor(); /** * Sets the localeJson for a Rule, if the localization rule exist it will be deep merged, this is to support the layered bundling * * @example PCore.getLocaleUtils().setLocaleForRule({ "fields" : {"First Name" : "Primero nome","Last Name" : "Ultimo nome"}}, "WORK-HOME!VIEW!PERSONALINFO"); * After the API call above the localization Store will have an entry for the "WORK-HOME!VIEW!PERSONALINFO" * { * "WORK-HOME!VIEW!PERSONALINFO" : { * "fields" : { * "First Name" : "Primero nome", * "Last Name" : "Ultimo nome" * } * }, * . * . * . * } * @param localeJson locale JSON for the rule. * @param localeRuleKey A key in the localization store for which we want to set the localeJSON * @function */ setLocaleForRule: (localeJson: AppStaticJson, localeRuleKey: string) => void; /** * @private * @description * Updates the locale store with the fields from the localeJson, for backward compatibility. */ updateLocaleStore: (localeJson: LocaleFields, localeRuleKey: string) => void; /** * * @param localeFields * @param localeRuleKey * @private * @description sanitizes the locale fields of Insight for backward compatibility. */ sanitizeLocaleField: (localeFields: LocaleFields, localeRuleKey: string) => void; /** * Gets localeJson for a rule * * @example PCore.getLocaleUtils().getLocaleForRule("WORK-HOME!VIEW!PERSONALINFO"); * If the localization store looks like below * { * "WORK-HOME!VIEW!PERSONALINFO" : { * "fields" : { * "First Name" : "Primero nome", * "Last Name" : "Ultimo nome" * } * } * } * The call to the API returns the below JSON * { * "fields" : { * "First Name" : "Primero nome", * "Last Name" : "Ultimo nome" * } * } * @param localeRuleKey - default value "@BASECLASS!GENERIC!PYGENERICFIELDS" A key in the localization store for which we want to get the localeJson. * @returns The fields object from localization store or undefined if passed key doesn't exists in localization store. * @function */ getLocaleForRule(localeRuleKey: string): Fields | undefined; /** * Resets the localization store to an empty object * * @example PCore.getLocaleUtils().resetLocaleStore(); * After this call, localization store is reset to an empty object {}. * @function */ resetLocaleStore: () => void; /** * Returns the localized value of string from the localization store. * * @example PCore.getLocaleUtils().getLocaleValue("First Name", "", "WORK-HOME!VIEW!PERSONALINFO"); * For a store which looks like the one below * { * "WORK-HOME!VIEW!PERSONALINFO" : { * "fields" : { * "First Name" : "Primero nome", * "Last Name" : "Ultimo nome" * } * } * } * The API call returns "Primero nome". * @param localeKey string to be localized * @param localePath Locale category in the localeJson. Default is always fields. * @param localeRuleKey Key in the Localization store. * @returns the localized value as a string * @function */ getLocaleValue(localeKey: string, localePath?: string, localeRuleKey?: string | null, componentName?: string | null): string; /** * Returns the localized value of string from the localization store. * * @param localeRuleKey key in the localized store * @param definedOnClass classID of the paragraph rule * @param paragraphName name of the paragraph rule * @returns the localized value as a string * @function * @private */ getParagraphLocaleValue(definedOnClass: string, paragraphName: string): string | null; /** * Returns the locale reference for the portal. * @param {string | null} optional portal name, if not provided default portal name would be used. * @returns {string} the localized value as a string * @function * @example PCore.getLocaleUtils().getPortalLocaleReference() * this returns a value for example `PORTAL!WEBPORTAL`. * warning: only use when pyLocaleReference is not available on portal dx response. */ getPortalLocaleReference(portal: string | null): string; /** * Returns the locale reference for the case type. * @param {string} caseClass Class of the case type, ex. APP-REACT-WORK. * @returns {string} the localized value as a string * @function * @example PCore.getLocaleUtils().getCaseLocaleReference('APP-REACT-WORK') * this returns a value for example `CASE!APP-REACT-WORK`. */ getCaseLocaleReference(caseClass: string): string | null; /** * Returns the locale version. * * @returns {number} the locale version of the runtime, initialized during bootstrap * @function * @example PCore.getLocaleUtils().getLocalizationVersion() * this returns a value for example 2 * @private * @deprecated */ getLocalizationVersion(): number; /** * Returns an array of localeJson objects for the respective locale references passed to the API. * Checks if the locale references are present in client localization store. If not present, makes a call to constellation service and gets the localeJson objects. * * @example LocalUtils.getLocaleJsons(["WORK-HOME!PAGE!PERSONALINFO", "WORK-HOME!CASE!FINANCIALSTATUS"]) * @param localeRefs Array of locale references rule names. * @returns Array of localeJson objects * @function * @private */ getLocaleJsons(localeRefs: string[]): Promise; /** * Loads all the locale resources from the locale references if the user locale is different from * the base locale. * * @example PCore.getLocaleUtils().loadLocaleResources(["WORK-HOME!PAGE!PERSONALINFO", "WORK-HOME!CASE!FINANCIALSTATUS"]); * @param localeRefs list of all the locale references to be loaded */ loadLocaleResources(localeRefs: string[]): Promise; /** * This API sets the timezone in the LocaleUtils. * * @example PCore.getLocaleUtils().setTimezone("Asia/Calcutta") * //This call sets the time zone to Asia/Calcutta * @param timezone TimeZone */ setTimezone(timezone: string): void; /** * This API returns the timezone in use if it is set, else returns the system/browser timezone. * @example PCore.getLocaleUtils().getTimeZoneInUse() * which should return "Asia/Calcutta" if "Asia/Calcutta" is set at requestor page. * * @returns the timezone * @function */ getTimeZoneInUse(): string; /** * Finding the placeholders' value in the error message keys like {1}, {2}.. * @param {Array} patternParts * @param {String} text - Error message key * @returns {Array} of placeholders which are to be replaced in translation * @private */ matchPatternWithText(patternParts: string[], text: string): string[] | null; /** * Returns localized error message for given input * @param {object} messages * @param {String} text - text to be found in message translations * @returns {String} * @private */ getLocalizedErrorMessage(messages: { [key: string]: string; }, text: string): string; /** * Replace placeholders with their value if all placeholders are found in localized string * @param {Array} placeholderArr * @param {String} translation * @returns {String} localized error message after replacing the placeholders * @private */ replacePlaceHolders(placeholderArr: string[], translation: string): string; /** * This API returns if the current user's locale present in the available locales in Constellation service * @example PCore.getLocaleUtils().isCurrentLocalePackAvailable() * which should return true/false based on if the current user's locale is available in Constellation service. * @returns true/false * @function * @private */ isCurrentLocalePackAvailable(): Promise; /** * This API returns translatations of all labels under `CosmosFields` * OR undefined if there is no translations present in locale store * @example Example for getBaseComponentLabels * PCore.getLocaleUtils().getLocalizationFields() * @returns {Fields | undefined} return translations under CosmosFields * @private */ getBaseComponentLabels: () => Fields | undefined; } declare const localeUtils: LocaleUtils; export { localeUtils, LocaleUtils };