0.9.0 • Published 3 months ago

ftl-tx v0.9.0

Weekly downloads
-
License
AGPL-3.0
Repository
-
Last release
3 months ago

CI Coverage Status npm version

ftl-tx

Simple library that converts .ftl to/from structured JSON with ICU Messages that Transifex can understand.

It has many limitations (see below).

Usage

import { ftlToJSON, JSONToFtl } from 'ftl-tx';
const ftl = `message = Hello, { $user }!`;
console.assert(JSONToFtl(ftlToJSON(ftl)).trim() === ftl);
console.log(ftlToJSON(ftl));

See tests/translate.test.js for various use cases.

Limitations

A limited set of features is supported, specifically:

  • attributes are translated into new messages, with the attribute name concatenated with the message key to create a new message key
  • fluent functions (including built-in functions) will be correctly transcoded to ICU and back, including when used as selectors, but obviously won't work in ICU format.
  • message referencing is not supported
  • terms are converted to variables, prefixed with FTLREF_ and with "-" replaced as "_"
  • All comments are ignored, except for message-bound comments prefixed tx:
  • Message nesting level is limited to 10 levels (using a variable/reference inside a variant value "costs" 0.5 level). This value is configurable and can be increased at a slight performance cost

Configuration

  • addTermsToFTL, whether to include terms in produced FTL file, defaults to true
  • commentPrefix, prefix used for comments, defaults to tx:
  • nestLimit, maximum message nesting level, defaults to 10
  • skipRefOnly, whether to exclude messages that only include a reference to another message value from JSON output
  • skipTerms, whether to exclude terms from JSON output

Examples

See tests/translate.test.js for examples.

0.9.0

3 months ago

0.8.0

3 months ago

0.7.0

3 months ago

0.3.0

1 year ago

0.5.0

12 months ago

0.4.1

1 year ago

0.4.0

1 year ago

0.6.0

12 months ago

0.5.1

12 months ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago