Classes: LocaleProvider

LocaleProvider

Provides a localization function getLocale to child components


new LocaleProvider()

Source:

Methods


getMessage(id, params)

Gets a locale message formatted by MessageFormat

Additional processing is enabled in this function that allows for more advanced formatting. You can now pass objects (jsx) or functions as param values, which makes the return value JSX wrapped into a .

When using functions, you can wrap a piece of copy between two variable placeholders, which will be passed to that function as argument.

Parameters:
Name Type Description
id

The id of the message to get

params

Parameters to pass to the MessageFormat compiler for this message

Source:
Example
foo {date} bar
 getMessage('foo.bar', { date: <time>2017</time> });

 foo {link}http://www.google.com/{_link}
 getMessage('foo.bar', { link: link => <a href={link}>{link}</a> });

 click {link}http://www.google.com/|here{_link}
 getMessage('foo.bar', { link: (url, text) => <a href={url}>{text}</a> });

hasMessage(id)

Checks if a message in the given MessageFormat messages bundle exists

Parameters:
Name Type Description
id

The id of the message to get

Source:
Returns:

true when the message exists

Type
boolean

initMessages()

Loads the locale from the getMessages function passed in props. Supports both a synchronous and asynchronous return value from getMessages. If the getMessages function returns a promise, we will set localeReady on this component's state to false so child components do not get rendered until the locale has completed loading.

When loading is complete, calls the onLocaleReady callback on props, if it is provided.

Source: