1 个不稳定版本
0.4.1 | 2023年1月10日 |
---|
#298 in 国际化 (i18n)
94 每月下载量
用于 usdpl-back
38KB
871 行
Gettext for Rust
目前路线图
- 解析 MO 文件(10.3)
- 解析元数据(6.2)
- 支持除 UTF-8 以外的编码
- 解析复数表达式(11.2.6)
- 路径查找正确吗?(11.2.3)
lib.rs
:
此 crate 是 GNU gettext 翻译框架在 Rust 中的重新实现。它允许您的 Rust 程序解析包含翻译的 GNU MO 文件并在用户界面中使用它们。
它与官方的 C 实现有几个不同之处。值得注意的是,此 crate 不会以任何方式依赖于全局区域设置(2.2),并且不会强制执行存储翻译目录的目录结构(11.2.3)。相反,用户将明确选择要使用的翻译目录。
此 crate 仍在开发中,可能在功能上不与原始实现相匹配。
有关确切的功能兼容性,请参阅 README 中的路线图。
示例
use std::fs::File;
use gettext::Catalog;
fn main() {
let f = File::open("french.mo").expect("could not open the catalog");
let catalog = Catalog::parse(f).expect("could not parse the catalog");
// Will print out the French translation
// if it is found in the parsed file
// or "Name" otherwise.
println!("{}", catalog.gettext("Name"));
}
依赖关系
~2.5MB
~32K SLoC