@eclipse-scout/core
Version:
Eclipse Scout runtime
104 lines • 5.33 kB
TypeScript
/// <reference types="jquery" />
import { Session, TextMap } from '../index';
export type TextMapType = Record<string, TextMap>;
export declare const texts: {
/**
* This default language is used whenever a new text is registered.
*/
defaultLanguage: string;
TEXT_KEY_REGEX: RegExp;
textsByLocale: TextMapType;
bootstrap(url: string | string[]): JQuery.Promise<any>;
/** @internal */
_setTextsByLocale(val: TextMapType): void;
/** @internal */
_handleBootstrapResponse(url: string, data: any): void;
init(model: Record<string, Record<string, string>>): void;
/**
* Links the texts of the given languageTag to make parent lookup possible (e.g. look first in de-CH, then in de, then in default).
*/
link(languageTag: string): void;
/**
* Creates an array containing all relevant tags.
*
* Examples:
* - 'de-CH' generates the array: ['de-CH', 'de', 'default']
* - 'de' generates the array: ['de', 'default']
* - 'default' generates the array: ['default']
*/
createOrderedLanguageTags(languageTag: string): string[];
/**
* Returns the (modifiable) TextMap for the given language tag.
* If no TextMap exists for the languageTag given, a new empty map is created.
* @returns the TextMap for the given languageTag. Never returns null or undefined.
*/
get(languageTag: string): TextMap;
/** @internal */
_get(languageTag: string): TextMap;
/**
* Registers the text map for the given locale.
* If there already is a text map registered for that locale, it will be replaced, meaning existing texts for that locale are deleted.
* @internal
*/
_put(languageTag: string, textMap: TextMap): void;
/**
* Extracts NLS texts from the DOM tree. Texts are expected in the following format:
*
* `<scout-text data-key="..." data-value="..." />`
*
* This method returns a map with all found texts. It must be called before scout.prepareDOM()
* is called, as that method removes all <scout-text> tags.
*/
readFromDOM(): Record<string, string>;
/**
* Returns the given text key in the form `'${textKey:AKey}'`.
*
* @param key the text key to convert (e.g. `'AKey'`)
* @returns the given text key in the form `'${textKey:AKey}'`
*/
buildKey(key: string): string;
/**
* Returns the text key (e.g. `'AKey'`) if the given text has the form `'${textKey:AKey}'`. Otherwise,
* the input is returned unchanged.
*
* @param value either an arbitrary text or a special string of the form `'${textKey:AKey}'`
* @returns the resolved text key or the unchanged value if the text key could not be extracted.
*/
resolveKey(value: string): string;
/**
* If the given text has the form `'${textKey:AKey}'`, the key is extracted and the text for this
* key in the given languages is resolved and returned. Otherwise, the input is returned unchanged.
*
* @param value either an arbitrary text or a special string of the form `'${textKey:AKey}'`
* @param languageTag the languageTag to use for the text lookup with the resolved key.
* @returns the resolved text in the given language or the unchanged text if the text key could not be extracted.
*/
resolveText(value: string, languageTag: string): string;
/**
* Converts the value of the specified property from the form `'${textKey:...}'` into a resolved text.
* The value remains unchanged if it does not match the {@linkplain texts#resolveText supported format}.
*
* @param object non-null object having a text property which may contain a text key (must not be null)
* @param textProperty name of the property on the given object which may contain a text key. By default, 'text' is used as property name.
* @param session session defining the locale to be used when resolving a text. Can be undefined when the given `object` has a session property, otherwise mandatory.
*/
resolveTextProperty(object: any, textProperty?: string, session?: Session): void;
/**
* Converts the values of the specified properties from the form `'${textKey:...}'` into a resolved text.
* A value remains unchanged if it does not match the {@linkplain texts#resolveText supported format}.
*
* @param object non-null object having a text property which may contain a text key (must not be null)
* @param textProperties names of the properties on the given object which may contain a text key.
* @param session session defining the locale to be used when resolving a text. Can be undefined when the given `object` has a session property, otherwise mandatory.
*/
resolveTextProperties(object: any, textProperties: string[], session?: Session): void;
/**
* Registers a texts map for a text key.
* The texts for the default language specified by {@link texts.defaultLanguage} are registered as default texts.
*
* @param key the text key under which the given textsArg map will be registered.
* @param textsArg an object with the languageTag as key and the translated text as value
*/
registerTexts(key: string, textsArg: Record<string, string>): void;
};
//# sourceMappingURL=texts.d.ts.map