9 releases

0.3.2 May 5, 2024
0.3.1 Jul 21, 2021
0.2.3 Nov 12, 2020
0.2.2 Feb 14, 2020
0.0.1 Aug 1, 2019

#313 in Internationalization (i18n)

Download history 411/week @ 2024-04-03 325/week @ 2024-04-10 377/week @ 2024-04-17 429/week @ 2024-04-24 713/week @ 2024-05-01 542/week @ 2024-05-08 561/week @ 2024-05-15 581/week @ 2024-05-22 518/week @ 2024-05-29 411/week @ 2024-06-05 727/week @ 2024-06-12 484/week @ 2024-06-19 437/week @ 2024-06-26 672/week @ 2024-07-03 961/week @ 2024-07-10 563/week @ 2024-07-17

2,694 downloads per month
Used in 4 crates

Apache-2.0 OR MIT

9KB
107 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 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, false)
}


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(vec![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

~2.2–3MB
~53K SLoC