https://github.com/willfarrell/fluent-transpiler
Transpile Fluent (ftl) files into optomized, tree-shakable, JavaScript EcmaScript Modules (esm).
https://github.com/willfarrell/fluent-transpiler
Last synced: 10 months ago
JSON representation
Transpile Fluent (ftl) files into optomized, tree-shakable, JavaScript EcmaScript Modules (esm).
- Host: GitHub
- URL: https://github.com/willfarrell/fluent-transpiler
- Owner: willfarrell
- License: mit
- Created: 2022-09-19T21:05:39.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-01T20:54:27.000Z (10 months ago)
- Last Synced: 2025-05-01T20:55:14.566Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 56.6 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fluent-transpiler
Transpile Fluent (ftl) files into optimized, tree-shakable, JavaScript EcmaScript Modules (esm).
## Install
```bash
npm i -D fluent-transpiler
```
## CLI
```bash
Usage: ftl [options]
Compile Fluent (.ftl) files to JavaScript (.js or .mjs)
Arguments:
input Path to the Fluent file to compile
Options:
--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.
--variable-notation 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 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 |
| 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. 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 |
```javascript
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')
```