https://github.com/alerque/handlebars-helper-fluent
Fluent based i18n helper for handlebars
https://github.com/alerque/handlebars-helper-fluent
handlebars handlebars-helpers i18n internationalization l10n localization npm-package
Last synced: about 2 months ago
JSON representation
Fluent based i18n helper for handlebars
- Host: GitHub
- URL: https://github.com/alerque/handlebars-helper-fluent
- Owner: alerque
- License: mit
- Created: 2019-09-11T13:19:53.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-05-06T18:20:31.000Z (about 3 years ago)
- Last Synced: 2025-08-22T10:04:10.837Z (10 months ago)
- Topics: handlebars, handlebars-helpers, i18n, internationalization, l10n, localization, npm-package
- Language: JavaScript
- Size: 119 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# handlebars-helper-fluent
[](https://www.npmjs.com/package/handlebars-helper-fluent)
[](https://travis-ci.com/alerque/handlebars-helper-fluent)
[Fluent][fluent] based i18n helper for [handlebars][handlebars].
# Usage
## From the Command Line
```sh
# 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
```js
// 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.
[fluent]: https://projectfluent.org/
[handlebars]: https://handlebarsjs.com/