How to Localize a Rust Application (fluent-rs)

You localize a Rust application by adding the `fluent-bundle` and `intl-memoizer` crates, loading `.ftl` resource files into a `FluentBundle`, and resolving messages with `FluentArgs`.

How to Localize a Rust Application (fluent-rs)

You localize a Rust application by adding the fluent-bundle and intl-memoizer crates, loading .ftl resource files into a FluentBundle, and resolving messages with FluentArgs.

[dependencies]
fluent-bundle = "0.16"
intl-memoizer = "0.5.1"
unic-langid = { version = "0.9.0", features = ["macros"] }
use fluent_bundle::{FluentBundle, FluentResource, FluentValue, FluentArgs};
use intl_memoizer::concurrent::IntlLangMemoizer;
use unic_langid::langid;

fn main() {
    let langid = langid!("en", "US");
    let mut bundle = FluentBundle::new_concurrent(vec![langid.clone()]);
    let res = FluentResource::try_new("hello = Hello, { $name }!".to_string()).unwrap();
    bundle.add_resource(res).unwrap();

    let mut args = FluentArgs::new();
    args.set("name", FluentValue::from("World"));

    let msg = bundle.get_message("hello").unwrap();
    let mut errors = vec![];
    let pattern = msg.value().unwrap();
    let mut out = String::new();
    pattern.format(&args, &mut out, &mut errors);
    println!("{}", out);
}