Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

handlebars-helper-fluent

0.4.0 • Public • Published

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.

Install

npm i handlebars-helper-fluent

DownloadsWeekly Downloads

1

Version

0.4.0

License

MIT

Unpacked Size

8.2 kB

Total Files

9

Last publish

Collaborators

  • avatar