ftl-tx
v0.16.0
Published
Converts .ftl to JSON with ICU Messages and back
Downloads
4,024
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 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 totrue
commentPrefix
, 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.