15 releases (breaking)
0.10.0 | May 23, 2023 |
---|---|
0.9.0 | Dec 12, 2021 |
0.8.0 | Jun 13, 2020 |
0.7.0 | Jun 12, 2019 |
0.0.5 | Nov 21, 2015 |
#52 in Internationalization (i18n)
4,221 downloads per month
Used in 16 crates
(12 directly)
350KB
674 lines
rust-pinyin
汉语拼音转换工具 Rust 版
Installation
Add this to your Cargo.toml
:
[dependencies]
pinyin = "0.10"
Documentation
API documentation can be found here: https://docs.rs/pinyin/
Usage
use pinyin::{ToPinyin, ToPinyinMulti};
fn main() {
let hans = "中国人";
// 无声调,输出 zhong guo ren
for pinyin in hans.to_pinyin() {
if let Some(pinyin) = pinyin {
print!("{} ", pinyin.plain());
}
}
println!();
// 包含声调,输出 zhōng guó rén
for pinyin in hans.to_pinyin() {
if let Some(pinyin) = pinyin {
print!("{} ", pinyin.with_tone());
}
}
println!();
// 声调用数字表示,输出 zho1ng guo2 re2n
for pinyin in hans.to_pinyin() {
if let Some(pinyin) = pinyin {
print!("{} ", pinyin.with_tone_num());
}
}
println!();
// 多音字,输出
// zho1ng zho4ng
// guo2
// re2n
for multi in hans.to_pinyin_multi() {
if let Some(multi) = multi {
for pinyin in multi {
print!("{} ", pinyin.with_tone_num());
}
println!();
}
}
}
Build
$ cargo build
Test
$ cargo test
Data
使用来自 pinyin-data 的拼音数据。
Related Projects
- hotoo/pinyin: 汉语拼音转换工具 Node.js/JavaScript 版。
- mozillazg/python-pinyin: 汉语拼音转换工具 Python 版。
- mozillazg/go-pinyin: 汉语拼音转换工具 Go 版。