Skip to main content

Class: MessageFormatDictionary

@ima/core.MessageFormatDictionary

Implementation of the Dictionary interface that relies on compiled MessageFormat localization messages for its dictionary.

Hierarchy

Constructors

constructor

new MessageFormatDictionary()

Initializes the dictionary.

Example

dictionary.get('home.hello', {GENDER: 'UNSPECIFIED'});

Overrides

Dictionary.constructor

Defined in

packages/core/src/dictionary/MessageFormatDictionary.ts:30

Properties

_dictionary

Protected _dictionary: DictionaryData

Defined in

packages/core/src/dictionary/MessageFormatDictionary.ts:18


_language

Protected _language: string

Defined in

packages/core/src/dictionary/MessageFormatDictionary.ts:17

Accessors

$dependencies

Static get $dependencies(): never[]

Returns

never[]

Defined in

packages/core/src/dictionary/MessageFormatDictionary.ts:20

Methods

_getScope

Private _getScope(key): null | LocalizationFunction

Retrieves the localization scope denoted by the provided partial key. This may be either an object representing a sub-group of location phrase generators, or a single generator if the provided keys denotes a single localization phrase

Parameters

NameTypeDescription
keystringThe key identifying the localization phrase. The key consists of at least two parts separated by dots. The first part denotes the name of the source JSON localization file, while the rest denote a field path within the localization object within the given localization file.

Returns

null | LocalizationFunction

The requested localization scope, or null if the specified scope does not exist.

Defined in

packages/core/src/dictionary/MessageFormatDictionary.ts:141


get

get(key, parameters?): string

Retrieves the localization phrase identified by the specified key, evaluates the phrase's placeholder expressions using the provided parameters and returns the result.

Parameters

NameTypeDescription
keystringThe key identifying the localization phrase. The key consists of at least two parts separated by dots. The first part denotes the name of the source JSON localization file, while the rest denote a field path within the localization object within the given localization file.
parameters?ObjectParametersThe map of parameter names to the parameter values to use. Defaults to an empty plain object.

Returns

string

The specified localization phrase with its placeholders evaluated using the provided parameters.

Overrides

Dictionary.get

Defined in

packages/core/src/dictionary/MessageFormatDictionary.ts:89


getLanguage

getLanguage(): string

Returns the ISO 639-1 language code of the language this dictionary was initialized with.

Returns

string

The language code representing the language of the localization phrases in this dictionary.

Overrides

Dictionary.getLanguage

Defined in

packages/core/src/dictionary/MessageFormatDictionary.ts:69


has

has(key): boolean

Tests whether the specified localization phrase exists in the dictionary.

Parameters

NameTypeDescription
keystringThe key identifying the localization phrase. The key consists of at least two parts separated by dots. The first part denotes the name of the source JSON localization file, while the rest denote a field path within the localization object within the given localization file.

Returns

boolean

true if the key exists and denotes a single localization phrase, otherwise false.

Overrides

Dictionary.has

Defined in

packages/core/src/dictionary/MessageFormatDictionary.ts:115


init

init(config): void

Initializes this dictionary with the provided language and localization phrases.

Parameters

NameTypeDescription
configDictionaryConfigThe dictionary configuration.

Returns

void

Overrides

Dictionary.init

Defined in

packages/core/src/dictionary/MessageFormatDictionary.ts:61