Registry / serialization / fluent-compiler

fluent-compiler

JSON →
library0.1.0jsnpmunverified

fluent-compiler (v0.1.0, stable pre-release) is a JavaScript transpiler for Project Fluent's FTL format. It compiles FTL messages into ES6 modules that export FluentBundle-compatible objects, shifting compilation from runtime to build time. Unlike the core `fluent` package (which ships a ~10kB runtime compiler), `fluent-compiler` outputs pre-compiled code with a ~1.2kB runtime dependency, reducing browser bundle size. It supports locale identifiers, optional AST input from `fluent-syntax`, configurable runtime imports, and Unicode isolation marks. Suitable for Node.js >=8.9.0 and build pipelines (Webpack, Rollup). Note: The runtime API is based on a draft PR (#360) and may change.

serializationweb-framework
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

The package is ESM-only and does not export a CommonJS default. In older Node.js or CJS environments, use dynamic import or transpile.

import { compile } from 'fluent-compiler'

The generated module uses ESM default export. If consumed from CJS, use dynamic import or compile with CommonJS output.

import messages from './compiled.ftl.js'

Main package does not export types; runtime types may be available from the runtime path or `fluent` package.

import type { FluentBundle } from 'fluent-compiler/runtime'

Shows end-to-end usage: compile FTL to JS, then import and use the pre-compiled bundle with format().

import { compile } from 'fluent-compiler' import fs from 'fs' // Read FTL source const ftlSource = fs.readFileSync('messages.it.ftl', 'utf8') // Compile to ES6 module string const compiledJS = compile('it', ftlSource, { runtimePath: 'fluent-compiler/runtime', useIsolating: true, withJunk: false }) // Write output fs.writeFileSync('messages.it.js', compiledJS) // In application code: import it from './messages.it.js' console.log(it.format('sync-signedout-account-title')) // Output: 'Connetti il tuo account Firefox'
Debug
Known footguns
breakingRuntime API is based on a draft PR (#360) and is subject to change. The current `format()`/`compound()` API may be revised in future releases.
gotchaThe compiled module should not be used with `bundle.addMessages()`; use `bundle.addResource()` instead, as `addMessages` requires runtime compilation.
gotchaThe compiled output is an ES6 module with a default export. It cannot be required via `require()` without transpilation or dynamic import.
gotchaThe `compile()` function accepts `source` as a string or a `Resource` AST object. When passing a string, ensure `fluent-syntax` is installed or provide a pre-parsed AST.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
12 hits · last 30 days
claudebot
4
gptbot
3
ahrefsbot
3
bingbot
2
Resources