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
每月下载量 2,704
在 4 个库中使用
9KB
107 行
Fluent
fluent-pseudo
是 Project Fluent(一个旨在释放自然语言翻译全部表达能力的本地化框架)的伪本地化 API 的 Rust 实现。
使用方法
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