9 个版本

0.3.2 2024年5月5日
0.3.1 2021年7月21日
0.2.3 2020年11月12日
0.2.2 2020年2月14日
0.0.1 2019年8月1日

国际化(i18n) 中排名 433

Download history 694/week @ 2024-05-03 629/week @ 2024-05-10 586/week @ 2024-05-17 549/week @ 2024-05-24 437/week @ 2024-05-31 597/week @ 2024-06-07 645/week @ 2024-06-14 374/week @ 2024-06-21 559/week @ 2024-06-28 820/week @ 2024-07-05 886/week @ 2024-07-12 570/week @ 2024-07-19 844/week @ 2024-07-26 614/week @ 2024-08-02 611/week @ 2024-08-09 555/week @ 2024-08-16

每月下载量 2,704
4 个库中使用

Apache-2.0 OR MIT

9KB
107

Fluent

fluent-pseudo 是 Project Fluent(一个旨在释放自然语言翻译全部表达能力的本地化框架)的伪本地化 API 的 Rust 实现。

crates.io Build Coverage Status

使用方法

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

依赖关系

~2.2–3MB
~54K SLoC