fluent-sequence
fluent-sequence
npm i fluent-sequence
Deprecated!
Renamed to @fluent/sequence 0.3.0
fluent-sequence

fluent-sequence

JavaScript implementation of Project Fluent

by projectfluent

0.3.0 (see all)License:Apache-2.0TypeScript:Not Found
npm i fluent-sequence
Readme

fluent-sequence

fluent-sequence provides mapping functions from string identifiers to FluentBundle instances taken from synchronous or asynchronous sequences. It's part of Project Fluent, a localization framework designed to unleash the expressive power of the natural language.

Installation

fluent-sequence 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 FluentSequence global).

npm install fluent-sequence

How to use

An ordered iterable of FluentBundle instances can represent the current negotiated fallback chain of languages. This iterable can be used to find the best existing translation for a given identifier.

fluent-sequence provides two mapping functions: mapBundleSync, and mapBundleAsync. They can be used to find the first FluentBundle in the given iterable which contains the translation with the given identifier. If the iterable is ordered according to the result of a language negotiation the returned FluentBundle contains the best available translation.

A simple function which formats translations based on the identifier might be implemented as follows:

import {mapBundleSync} from "fluent-sequence";

function formatString(id, args) {
    // contexts is a negotiated iterable of FluentBundle instances.
    let ctx = mapBundleSync(contexts, id);

    if (ctx === null) {
        return id;
    }

    let msg = ctx.getMessage(id);
    return ctx.format(msg, args);
}

When passing a synchronous iterator to mapBundleSync, wrap it in CachedSyncIterable from the cached-iterable package. When passing an asynchronous iterator to mapBundleAsync, wrap it in CachedAsyncIterable. This allows multiple calls to mapContext* without advancing and eventually depleting the iterator.

Learn more

Find out more about Project Fluent at projectfluent.org, including documentation of the Fluent file format (FTL), links to other packages and implementations, and information about how to get involved.

Downloads/wk

73

GitHub Stars

739

LAST COMMIT

7mos ago

MAINTAINERS

1

CONTRIBUTORS

50

OPEN ISSUES

69

OPEN PRs

13
VersionTagPublished
0.3.0
latest
3yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate