ftl-tx
v0.17.0
Published
Converts .ftl to JSON with ICU Messages and back
Readme
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 translated to ICU and back, including when used as selectors, but won't work in ICU format.
- 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 a produced FTL file, defaults totruecommentPrefix, prefix used for comments, defaults totx:nestLimit, maximum message nesting level, defaults to 10skipRefOnly, whether to exclude from JSON output messages that only include a reference (to another message or to a term/variable)skipTerms, whether to exclude terms from JSON output
Examples
See tests/translate.test.js for examples.
