Using Fluent as a JS Module

Hi Fluenters!

I’d like to use Fluent in a small vanilla JS project that doesn’t need a build system at all for DOM localization. Ideally I would just import a JS module with no additional build steps.

Is that possible with Fluent.js?

thanks!

This could be useful in your scenario: https://www.pika.dev/npm/@pika/web

Hi @fabrice! :wave: Sorry for the long wait, I was away on a extended leave of absence.

All fluent.js packages available on npm are bundled into the UMD format, which makes them suitable to be included as regular <script src=".."></script> scripts in HTML.

For instance, you could install https://www.npmjs.com/package/@fluent/bundle and link to or copy node_modules/@fluent/bundle/index.js (the modern JS build) or node_modules/@fluent/bundle/compat.js (the Firefox 52+, Chrome 55+ build).

However, Fluent is a collection of packages operating on increasing levels of abstarction. @fluent/bundle provides the FluentBundle API responsible for parsing and formatting. It won’t manage a language fallback chain for you nor will it make it any easier to localize DOM nodes. Above it sits @fluent/dom with APIs suitable for localizing vanilla DOM, and then there’s also @fluent/web which packages it all into a single file which also actually initializes the @fluent/dom APIs and exposes them under document.l10n.

I should also add that we currently don’t have a good story about developing and maintaining both @fluent/dom and @fluent/web. They’re both experiments and @zbraniecki has been keeping them up to date, but they’re not currently used in Firefox. I hope that we’ll have a better support plan for them in 2020.