Skip to main content
Home

latest
It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
64%
Published
9 months ago (1.1.0)

Fluent Project rapid integration

Rapidly support Fluent Project's translation in your web application. Both client-side and server-side applications are supported.

That is an updated version of com.hydroper.ftl.

Getting Started

Install dependency:

npx jsr add @hydroper/fluent

Example TypeScript:

import { FluentBox } from "@hydroper/fluent";

class Main
{
    fluentBox: FluentBox;

    constructor()
    {
        this.fluentBox = new FluentBox({
            locales: ["en"],
            fallbacks: {
                // "pt-BR": ["en"],
            },
            defaultLocale: "en",

            source: "res/lang",
            files: [
                "_", // res/lang/LANG/_.ftl
            ],

            clean: true,

            // specify either 'http' or 'fileSystem' as load method
            method: "fileSystem",
        });
        this.initialize();
    }

    async initialize()
    {
        if (!(await this.fluentBox.load()))
        {
            // failed to load
            return;
        }

        console.log(this.fluentBox.getMessage("hello", { to: "Diantha" }));
    }
}

new Main();

Example FTL file at res/lang/en/_.ftl:

hello = Hello, { $to }!

Server Usage

Usually, for server applications, set the clean option to false and clone the FluentBox object when necessary by invoking fluentBox.clone(); to change the current locale.

The fluentBox.clone(); method clones the FluentBox object, but still re-uses resources from the original object, avoiding resource duplication.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@hydroper/fluent

Import symbol

import * as fluent from "@hydroper/fluent";
or

Import directly with a jsr specifier

import * as fluent from "jsr:@hydroper/fluent";

Add Package

pnpm i jsr:@hydroper/fluent
or (using pnpm 10.8 or older)
pnpm dlx jsr add @hydroper/fluent

Import symbol

import * as fluent from "@hydroper/fluent";

Add Package

yarn add jsr:@hydroper/fluent
or (using Yarn 4.8 or older)
yarn dlx jsr add @hydroper/fluent

Import symbol

import * as fluent from "@hydroper/fluent";

Add Package

vlt install jsr:@hydroper/fluent

Import symbol

import * as fluent from "@hydroper/fluent";

Add Package

npx jsr add @hydroper/fluent

Import symbol

import * as fluent from "@hydroper/fluent";

Add Package

bunx jsr add @hydroper/fluent

Import symbol

import * as fluent from "@hydroper/fluent";