Package Exports
- messageformat
- messageformat/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (messageformat) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
A Polyfill for Intl.MessageFormat
This library provides a runtime for the ECMA-402 Intl.MessageFormat proposal, which is built on top of the developing Unicode MessageFormat 2.0 specification, "MF2".
NOTE: This means that the v4 release of the
messageformat
package has an entirely different API compared to its earlier major releases, which were built on top of ICU MessageFormat, aka "MF1". For that, please see@messageformat/core
instead.
Usage
npm install --save-exact messageformat@next
import { MessageFormat } from 'messageformat';
Intl.MessageFormat = MessageFormat;
In addition to supporting MF2 syntax, compilers and formatting function runtimes are also provided for ICU MessageFormat and Fluent messages:
API
The API provided by this Intl.MessageFormat polyfill is current as of
2022-07-13.
The static MessageFormat.parseResource()
method is not yet provided,
as the message resource syntax is still under development.
const locale = 'en-US';
const msg = '{Today is {$today :datetime dateStyle=medium}}';
const mf = new Intl.MessageFormat(msg, locale);
mf.resolveMessage({ today: new Date('2022-02-02') }).toString();
// 'Today is Feb 2, 2022'
For more information on additional types and functions provided by this package, see the API documentation site.