Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fluent-compiler

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fluent-compiler

`fluent-compiler` provides a JavaScript stringifier for [Fluent]. Essentially, it's a transpiler that allows converting files from Fluent's `ftl` format to JavaScript, outputting an ES6 module that exports a [FluentBundle][bundle].

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
51
decreased by-20.31%
Maintainers
1
Weekly downloads
 
Created
Source

fluent-compiler

fluent-compiler provides a JavaScript stringifier for Fluent. Essentially, it's a transpiler that allows converting files from Fluent's ftl format to JavaScript, outputting an ES6 module that exports a FluentBundle.

The difference between this package and the core fluent package is that the latter will need to compile your messages on the client, and is about 10kB when compressed. The runtime component of fluent-compiler is about 1.2kB, and it lets you take care of the message compilation during your build.

NOTE: The current runtime implements the format()/compound() API of Fluent.js PR #360, which is likely still to get revised.

API

import { compile } from 'fluent-compiler'

compile(locales, source, options = {}) => string

ParamTypeDescription
locales`stringstring[]
source`stringResource`
optionsCompilerOptionsCompiler options object (optional)
CompilerOptions
OptionTypeDefaultDescription
runtimeGlobalsstring[]['DATETIME', 'NUMBER']Identifiers of global functions available in the runtime
runtimePathstring'fluent-compiler/runtime'Path for the runtime dependency
useIsolatingbooleantrueWrap placeables with Unicode FSI & PDI isolation marks
withJunkbooleanfalseInclude unparsed source as comments in the output

The string returned by compile() is the string representation of an ES6 module, which in turn exports bundle and resource interfaces for the source messages. Note that the bundle.addMessages() is not included, as it requires message compilation; use bundle.addResource() instead:

import bundle from './default_messages'
import { resource } from './extra_messages'

bundle.addResource(resource, { allowOverrides: true })
// bundle now includes all default_messages as well as extra_messages,
// with the latter overriding the former

Usage

Fluent source file messages.it.ftl:

-sync-brand-name = {$capitalization ->
   *[uppercase] Account Firefox
    [lowercase] account Firefox
}

sync-dialog-title = {-sync-brand-name}
sync-headline-title =
    {-sync-brand-name}: il modo migliore
    per avere i tuoi dati sempre con te

# Explicitly request the lowercase variant of the brand name.
sync-signedout-account-title =
    Connetti il tuo {-sync-brand-name(capitalization: "lowercase")}

Build script:

import { compile } from 'fluent-compiler'
import fs from 'fs'

const src = fs.readFileSync('messages.it.ftl')
const js = compile('it', src)
fs.writeFileSync('messages.it.js', js)

Application code:

import it from './messages.it'

it.format('sync-signedout-account-title')
// 'Connetti il tuo account Firefox'

Polyfills

The ES6 module output by compile() will probably need to itself be transpiled, as it uses Object Spread syntax (currently at Stage 3). Furthermore, the runtime may need polyfills for the Intl objects and Object.entries (used by the bundle's messages getter). In particular, intl-pluralrules patches some of the deficiencies in current browsers.

Keywords

FAQs

Package last updated on 02 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc