6 releases

0.2.3 Nov 12, 2020
0.2.2 Feb 14, 2020
0.2.0 Dec 13, 2019
0.1.0 Nov 26, 2019
0.0.1 Aug 1, 2019

#97 in Internationalization (i18n)

Download history 23/week @ 2020-08-02 47/week @ 2020-08-09 26/week @ 2020-08-16 38/week @ 2020-08-23 20/week @ 2020-08-30 45/week @ 2020-09-06 39/week @ 2020-09-13 29/week @ 2020-09-20 25/week @ 2020-09-27 29/week @ 2020-10-04 28/week @ 2020-10-11 24/week @ 2020-10-18 29/week @ 2020-10-25 19/week @ 2020-11-01 52/week @ 2020-11-08 71/week @ 2020-11-15

129 downloads per month
Used in fluent

Apache-2.0/MIT

7KB
102 lines

Fluent

fluent-pseudo is a Rust implementation of the pseudolocalization API for [Project Fluent][], a localization framework designed to unleash the entire expressive power of natural language translations.

crates.io Build Status Coverage Status

Usage

use fluent_bundle::{FluentBundle, FluentResource};
use unic_langid::langid;
use fluent_pseudo::transform;

fn transform_wrapper(s: &str) -> Cow<str> {
    // Not flipped and elongated pseudolocalization.
    transform(s, false, true)
}


fn main() {
    let ftl_string = "hello-world = Hello, world!".to_owned();
    let res = FluentResource::try_new(ftl_string)
        .expect("Could not parse an FTL string.");

    let langid_en = langid!("en");
    let mut bundle = FluentBundle::new(&[langid_en]);

    // Set pseudolocalization
    bundle.set_transform(Some(transform_wrapper));

    bundle.add_resource(&res)
        .expect("Failed to add FTL resources to the bundle.");

    let msg = bundle.get_message("hello-world")
        .expect("Failed to retrieve a message.");
    let val = msg.value.expect("Message has no value.");

    let mut errors = vec![];
    let value = bundle.format_pattern(val, None, &mut errors);

    assert_eq!(&value, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ!");
}

Dependencies

~1–1.4MB
~40K SLoC