Fluent Handlebars runtime helper: An extension crate for Fluent Templates
The fluent_templates
crate includes a helper for the
Handlebars template framework that lets you provide values for
Fluent placeables at build time.
fluent-handlebars-runtime
adds a helper that resolves placeables using the data hash you pass
into the Handlebars render_template
method.
For example, if your FTL files look like this:
# /resources/locale/en-US/app.ftl
into-place = One does not simply walk into {$place}
# /resources/locale/fr/app.ftl
into-place = On ne marche pas simplement à {$place}
You can then pass the replacement values at runtime:
# use Handlebars;
# use FluentHandlebars;
# use ArcLoader;
# use langid;
# let loader = builder
# .customize
# .build
# .unwrap;
#
let data = json!;
let mut handlebars = new;
handlebars.register_helper;
assert_eq!;
let data = json!;
assert_eq!;
This allows you to substitute values into your localized strings that can only be known at runtime.
By convention, we call this helper "t" in the interest of keeping templates terse, but you can use a more verbose identifier (e.g. "translate" or "localize") if you find that more readable.
# use Handlebars;
# use FluentHandlebars;
# use ArcLoader;
# use langid;
# let loader = builder
# .customize
# .build
# .unwrap;
#
# let data = json!;
#
# let mut handlebars = new;
handlebars.register_helper;
assert_eq!;