@messageformat/fluent
TypeScript icon, indicating that this package has built-in type declarations

0.8.0 • Public • Published

@messageformat/fluent

This library provides conversion and compatibility tools for using Fluent resources with the Unicode MessageFormat 2.0 -based ECMA-402 Intl.MessageFormat proposal.

The Fluent message representation relies on @fluent/syntax, while the MessageFormat 2 representation uses messageformat@next.

This package is distributed only as an ES module.

Usage

npm install @messageformat/fluent
import { fluentToResource } from '@messageformat/fluent';

const locale = 'en-US';
const src = 'msg = Today is {DATETIME($today, dateStyle: "medium")}\n';

const resource = fluentToResource(src, locale);

const msg = resource.get('msg').get('');

msg.format({ today: new Date('2022-02-02') });
// 'Today is Feb 2, 2022'

msg.formatToParts({ today: new Date('2022-02-02') });
// [
//   MessageLiteral { type: 'literal', value: 'Today is ' },
//   MessageDateTime {
//     type: 'datetime',
//     value: 2022-02-02T00:00:00.000Z,
//     options: { localeMatcher: 'best fit', dateStyle: 'medium' },
//     source: '$today :DATETIME'
//   }
// ]

API

import {
  fluentToMessage,
  fluentToResource,
  fluentToResourceData,
  getFluentFunctions,
  messageToFluent,
  resourceToFluent
} from '@messageformat/fluent';

import type {
  FluentMessageResource,
  FluentMessageResourceData
} from '@messageformat/fluent';

For more information, see the API documentation site.

Package Sidebar

Install

npm i @messageformat/fluent

Weekly Downloads

87

Version

0.8.0

License

Apache-2.0

Unpacked Size

47.6 kB

Total Files

16

Last publish

Collaborators

  • eemeli