gecko-dev/third_party/rust/fluent-pseudo
Matjaz Horvat ee30b4c3f1 Bug 1711028: Update the "accented" pseudo l10n strategy with markers. r=dminor,flod
The updated strategy wraps parts of strings in square brackets, and hence
"marks" the beginning and the end of the part of the string.

Differential Revision: https://phabricator.services.mozilla.com/D121078
2021-08-02 16:44:25 +00:00
..
src Bug 1711028: Update the "accented" pseudo l10n strategy with markers. r=dminor,flod 2021-08-02 16:44:25 +00:00
.cargo-checksum.json Bug 1711028: Update the "accented" pseudo l10n strategy with markers. r=dminor,flod 2021-08-02 16:44:25 +00:00
Cargo.toml Bug 1711028: Update the "accented" pseudo l10n strategy with markers. r=dminor,flod 2021-08-02 16:44:25 +00:00
LICENSE-APACHE Bug 1711028: Update the "accented" pseudo l10n strategy with markers. r=dminor,flod 2021-08-02 16:44:25 +00:00
LICENSE-MIT Bug 1711028: Update the "accented" pseudo l10n strategy with markers. r=dminor,flod 2021-08-02 16:44:25 +00:00
README.md Bug 1711028: Update the "accented" pseudo l10n strategy with markers. r=dminor,flod 2021-08-02 16:44:25 +00:00

README.md

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 and test 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, "Ħḗḗŀŀǿǿ Ẇǿǿřŀḓ!");
}