fluent-transpiler

Transpile Fluent (ftl) files into optimized, tree-shakable, JavaScript EcmaScript Modules (esm).


Keywords
Fluent, @fluent, ftl, localization, l10n, internationalization, i18n, ast, compiler, transpiler
License
MIT
Install
npm install fluent-transpiler@0.4.1

Documentation

fluent-transpiler

Transpile Fluent (ftl) files into optimized, tree-shakable, JavaScript EcmaScript Modules (esm).


GitHub Actions unit test status GitHub Actions dast test status GitHub Actions perf test status GitHub Actions SAST test status GitHub Actions lint test status
npm version npm install size npm weekly downloads npm provenance
Open Source Security Foundation (OpenSSF) Scorecard SLSA 3 Checked with Biome Conventional Commits code coverage

Install

npm i -D fluent-transpiler

CLI

Usage: ftl [options] <input>

Compile Fluent (.ftl) files to JavaScript (.js or .mjs)

Arguments:
  input                                   Path to the Fluent file to compile

Options:
  --locale <locale...>                    What locale(s) to be used. Multiple can be set to allow for fallback. i.e. en-CA
  --comments                              Include comments in output file.
  --include-key <keys...>                 Allowed messages to be included. Default to include all.
  --exclude-key <keys...>                 Ignored messages to be excluded. Default to exclude none.
  --exclude-value <value>                 Set message to an empty string when it contains this value.
  --variable-notation <variableNotation>  What variable notation to use with exports (choices: "camelCase", "pascalCase", "constantCase",
                                          "snakeCase", default: "camelCase")
  --disable-minify                        If disabled, all exported messages will have the same interface `(params) => ({value, attributes})`.
  --use-isolating                         Wrap placeable with \u2068 and \u2069.
  -o, --output <output>                   Path to store the resulting JavaScript file. Will be in ESM.
  -h, --help                              display help for command

NodeJS

Option Description
locale What locale(s) to be used. Multiple can be set to allow for fallback. i.e. en-CA
comments Include comments in output file. Default: true
includeKey Array of message keys to include. Default: [] (include all)
excludeKey Array of message keys to exclude. Default: [] (exclude none)
excludeValue Set message to an empty string when it contains this value. Default: undefined
disableMinify If disabled, all exported messages will have the same interface (params) => ({value, attributes}). Default: each exported message could be a different type based on what is needed to generate the message (string, object, () => '', () => ({}))
errorOnJunk Throw error when Junk is parsed. Default: true
variableNotation What variable notation to use with exports. Choices: camelCase, pascalCase, snakeCase, constantCase. Default: camelCase
useIsolating Wrap placeable with \u2068 and \u2069. Default: false
exportDefault Allows the overwriting of the export default to allow for custom uses. Default: See code
import { readFile, writeFile } from 'node:fs/promises'
import fluentTranspiler from 'fluent-transpiler'

const ftl = await readFile('./path/to/en.ftl', { encoding: 'utf8' })
const js = fluentTranspiler(ftl, { locale: 'en-CA' })
await writeFile('./path/to/en.mjs', js, 'utf8')