Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including handlebars-helper-fluent with all npm packages installed. Try it out:

var handlebarsHelperFluent = require("handlebars-helper-fluent")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

handlebars-helper-fluent v0.4.0

Fluent based i18n helper for Handlebars

handlebars-helper-fluent

NPM Travis CI

Fluent based i18n helper for handlebars.

Usage

From the Command Line

# Install the Handlebars CLI tool and this plugin
$ npm install hbs-cli handlebars-helper-fluent

# Invoke handlebars to output from a template by specifying this plugin plus data
# about what language and where to find the FTL file
$ hbs -D '{"lang": "en", "ftl": "en.ftl"}' --helper handlebars-helper-fluent -s template.hbs

From Javascript

// Load packages
var Handlebars = require('handlebars');
var Fluent = require('handlebars-helper-fluent');

// Setup data about what language and where to find the FTL file
var context = {
  lang: 'en',
  ftl: 'en.ftl'
};

// Register the helper
Fluent.register(Handlebars);

// Use the way you would normally use Handlebars
var template = Handlebars.compile('Hello {{fluent "world"}}!');
template(context);

API

Requires a lang parameter to be set in content.

Optionally uses the ftl parameter as a filename to read from, defaults to $lang.ftl.

  • {{fluent "index"}} inline helper, take string as the key to lookup in Fluent. Context data may be adjusted with hash values.

  • {{#fluent "index"}}{{/fluent}} block helper that can contain instances of fluentparam.

  • {{#fluentparam "key"}}value{{/fluentparam}} block helper that can set data values for use its parent context.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free