Skip to content

Files

fluent-bundle

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jul 27, 2021
Feb 28, 2024
Apr 3, 2024
Apr 20, 2020
Jan 23, 2020
Mar 13, 2023
Feb 28, 2024
Jul 28, 2021
Feb 28, 2024
Sep 13, 2021

@fluent/bundle

@fluent/bundle is a JavaScript implementation of Project Fluent, optimized for runtime performance.

Installation

@fluent/bundle can be used both on the client-side and the server-side. You can install it from the npm registry or use it as a standalone script (as the FluentBundle global).

npm install @fluent/bundle

How to use

The FluentBundle constructor provides the core functionality of formatting translations from FTL files.

import { FluentBundle, FluentResource } from "@fluent/bundle";

let resource = new FluentResource(`
-brand-name = Foo 3000
welcome = Welcome, {$name}, to {-brand-name}!
`);

let bundle = new FluentBundle("en-US");
let errors = bundle.addResource(resource);
if (errors.length) {
  // Syntax errors are per-message and don't break the whole resource
}

let welcome = bundle.getMessage("welcome");
if (welcome.value) {
  bundle.formatPattern(welcome.value, { name: "Anna" });
  // → "Welcome, Anna, to Foo 3000!"
}

The API reference is available at https://projectfluent.org/fluent.js/bundle.

Compatibility

@fluent/bundle requires the following Intl formatters:

  • Intl.DateTimeFormat (standard, well-supported)
  • Intl.NumberFormat (standard, well-supported)
  • Intl.PluralRules (standard, well-supported)

See also the Compatibility article on the fluent.js wiki.