[][src]Macro handlebars_fluent::simple_loader

macro_rules! simple_loader {
    ($constructor:ident, $location:expr, $fallback:expr) => { ... };
    ($constructor:ident, $location:expr, $fallback:expr, core: $core:expr, customizer: $custom:expr) => { ... };
}

Loads Fluent data at runtime via lazy_static to produce a loader.

Usage:

use handlebars_fluent::*;

simple_loader!(create_loader, "./tests/locales/", "en-US");

fn init() {
    let loader = create_loader();
    let helper = FluentHelper::new(loader);
}

$constructor is the name of the constructor function for the loader, $location is the location of a folder containing individual locale folders, $fallback is the language to use for fallback strings.

Some Fluent users have a share "core.ftl" file that contains strings used by all locales, for example branding information. They also may want to define custom functions on the bundle.

This can be done with an extended invocation:

use handlebars_fluent::*;

simple_loader!(create_loader, "./tests/locales/", "en-US", core: "./tests/core.ftl",
               customizer: |bundle| {bundle.add_function("FOOBAR", |_values, _named| {unimplemented!()}); });

fn init() {
    let loader = create_loader();
    let helper = FluentHelper::new(loader);
}

The constructor function is cheap to call multiple times since all the heavy duty stuff is stored in shared statics.