Debian Codegraph @

third_party/rust/fluent-pseudo/README.md

raw
1 # Fluent
2
3 `fluent-pseudo` is a Rust implementation of the pseudolocalization API for [Project Fluent](https://projectfluent.org/), a localization
4 framework designed to unleash the entire expressive power of natural language
5 translations.
6
7 [![crates.io](https://meritbadge.herokuapp.com/fluent-pseudo)](https://crates.io/crates/fluent-pseudo)
8 [![Build and test](https://github.com/projectfluent/fluent-rs/workflows/Build%20and%20test/badge.svg)](https://github.com/projectfluent/fluent-rs/actions?query=branch%3Amaster+workflow%3A%22Build+and+test%22)
9 [![Coverage Status](https://coveralls.io/repos/github/projectfluent/fluent-rs/badge.svg?branch=master)](https://coveralls.io/github/projectfluent/fluent-rs?branch=master)
10
11 Usage
12 -----
13
14 ```rust
15 use fluent_bundle::{FluentBundle, FluentResource};
16 use unic_langid::langid;
17 use fluent_pseudo::transform;
18
19 fn transform_wrapper(s: &str) -> Cow<str> {
20 // Not flipped and elongated pseudolocalization.
21 transform(s, false, true, false)
22 }
23
24
25 fn main() {
26 let ftl_string = "hello-world = Hello, world!".to_owned();
27 let res = FluentResource::try_new(ftl_string)
28 .expect("Could not parse an FTL string.");
29
30 let langid_en = langid!("en");
31 let mut bundle = FluentBundle::new(vec![langid_en]);
32
33 // Set pseudolocalization
34 bundle.set_transform(Some(transform_wrapper));
35
36 bundle.add_resource(&res)
37 .expect("Failed to add FTL resources to the bundle.");
38
39 let msg = bundle.get_message("hello-world")
40 .expect("Failed to retrieve a message.");
41 let val = msg.value.expect("Message has no value.");
42
43 let mut errors = vec![];
44 let value = bundle.format_pattern(val, None, &mut errors);
45
46 assert_eq!(&value, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ!");
47 }
48 ```