fune/third_party/rust/fluent-bundle/examples/selector.rs
Zibi Braniecki fc2dfec886 Bug 1560038 - Vendor in fluent-rc. r=emilio
--HG--
extra : amend_source : c535f2190b8a11ae36ee8a00278b9c3e1f0c9e71
2020-03-11 08:45:00 +02:00

41 lines
1.2 KiB
Rust

use fluent_bundle::{FluentArgs, FluentBundle, FluentResource, FluentValue};
fn main() {
let ftl_string = String::from(
"
hello-world = Hello { $missing ->
*[one] World
[two] Moon
}
hello-world2 = Hello { $name ->
*[world] World
[moon] Moon
}
",
);
let res = FluentResource::try_new(ftl_string).expect("Could not parse an FTL string.");
let mut bundle = FluentBundle::default();
bundle
.add_resource(res)
.expect("Failed to add FTL resources to the bundle.");
let msg = bundle
.get_message("hello-world")
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value.expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
println!("{}", value);
let mut args = FluentArgs::new();
args.insert("name", FluentValue::from("moon"));
let msg = bundle
.get_message("hello-world2")
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value.expect("Message has no value.");
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
println!("{}", value);
}